I am trying to get the annotation (weblink) defined in the PDF on a specific text field.
I am able to get the references from reader with page.annotations but when I call AddWebLink on the XRect object with the rect parameters, It shows at a different locations.
In general, I need a solution on how I can grab the fields which are of type LINK and manipulate that link.
Hope I am able to explain the problem. Below is the sample code.
PdfAcroForm acroform = reader1.AcroForm; // reader1 is a pdfdocument which I am opening in Modify mode var af = acroform.Fields; for (int i = 0; i < reader1.PageCount; i++) { PdfPage page = reader1.Pages[i]; for (int p = 0; p < 25; p++) { PdfAnnotation textAnnot = page.Annotations[p]; PdfItem type = (page.Annotations[p].Elements["/Subtype"]); string content = textAnnot.Contents; if (type.ToString() == "/Link") { XFont fontNormal = new XFont("Calibri", 10, XFontStyle.Regular); using (XGraphics gfx = XGraphics.FromPdfPage(page)) { var xrect = new XRect(textAnnot.Rectangle.X1, textAnnot.Rectangle.Y1, textAnnot.Rectangle.X2, textAnnot.Rectangle.Y2); var rect = gfx.Transformer.WorldToDefaultPage(xrect); var pdfrect = new PdfRectangle(rect); page.AddWebLink(pdfrect, "www.google.com"); gfx.DrawString("This Is a link", fontNormal, XBrushes.Black, xrect, XStringFormats.TopLeft); } } } } reader1.Save("E:\\pdfsharp\\pdftest.pdf");
Please suggest.
|