Hi Aspose Team,
Using the below mentioned code we are trying to create hyperlinks in attached PDF file(test_coverage.pdf) “coverage” text. In the PDF file “coverage” text is present in 3 places. As per the below code hyperlinks needs to create all 3 “coverage” text. But, its creating only first 1 and 3 occurrence “coverage” text and its not creating hyperlink 2nd occurrence “coverage” text.
Actually, the issue is 1st and 2nd occurrence “coverage” text are in same line. Hence while searching 2nd occurrence “coverage” text Aspose returning again the 1st occurrence text position only, hence 2nd occurrence “coverage” text hyperlink also creating on top of 1st occurrence “coverage” text.
int[] dashArray = { };
String[] LEArray = { };
Aspose.Pdf.License obj = new Aspose.Pdf.License();
obj.SetLicense("Aspose.Pdf.lic");
System.Drawing.Color transparent = System.Drawing.Color.Transparent;
System.Drawing.Color blue = System.Drawing.Color.Blue;
//open document
PdfContentEditor editor = new PdfContentEditor();
editor.BindPdf("D:\\WebSite1\\test_coverage.pdf");
//create TextAbsorber object to find all instances of the input search phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("Coverage");
//accept the absorber for all the pages
editor.Document.Pages[2].Accept(textFragmentAbsorber);
//get the extracted text fragments
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
//loop through the fragments
foreach (TextFragment textFragment in textFragmentCollection)
{
textFragment.TextState.ForegroundColor = System.Drawing.Color.Blue;
System.Drawing.Rectangle rect = new System.Drawing.Rectangle((int)textFragment.Rectangle.LLX, (int)Math.Round(textFragment.Rectangle.LLY), (int)Math.Round(textFragment.Rectangle.Width + 2), (int)Math.Round(textFragment.Rectangle.Height + 1));
editor.CreateJavaScriptLink("this.getURL('www.google.com',true);", rect, 2, transparent);
editor.CreateLine(rect, "", (float)textFragment.Rectangle.LLX + 1, (float)textFragment.Rectangle.LLY - 1, (float)textFragment.Rectangle.URX, (float)textFragment.Rectangle.LLY - 1, 2, 1, blue, "S", dashArray, LEArray);
}
//Save & Close the document
editor.Save("D:\\WebSite1\\output.pdf");
editor.Close();
Please let us know is this issue with Aspose.PDF tool (or) PDF file.
Why Aspose.PDF is not returning the 2nd occurrence “coverage” text position? How to make it create hyperlink in the 2nd occurrence “coverage” text?
Thanks & Regards,
Ganesan. B