We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Issue while creating the link on PDF file

I noticed an Exception “Index was outside the bounds of the array” when creating an link with text color change using AsposePDF v19.1.0.0(this issue exits in AsposePDF v18.10.0.0 also)

Please see the attached “linking-issue.pdf”.

I used following code to create link with text color change using Aspose.PDF v19.1.0.0

//***Code Start
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.Embedded = true;
Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(textBox1.Text);
Aspose.Pdf.Page page = pdf.Pages[1];
Aspose.Pdf.Rectangle AnnotRect = new Aspose.Pdf.Rectangle(80, 540, 270, 560);
LinkAnnotation link = new LinkAnnotation(page, AnnotRect);
XYZExplicitDestination mag = new XYZExplicitDestination(page, 0, page.MediaBox.Height, 0);
link.Action = new GoToAction(mag);
System.Drawing.Color color2 = System.Drawing.ColorTranslator.FromHtml("#008000");
link.Color = Aspose.Pdf.Color.FromRgb(color2);
Border border = new Border(link);
border.Style = Aspose.Pdf.Annotations.BorderStyle.Solid;
link.Border = border;
foreach (Annotation annotation in page.Annotations)
if (annotation is LinkAnnotation)
Aspose.Pdf.Rectangle rect = annotation.Rect;
TextFragmentAbsorber absorber = new TextFragmentAbsorber();
absorber.TextSearchOptions.Rectangle = rect;
foreach (TextFragment textFragment in absorber.TextFragments)
System.Drawing.Color color = System.Drawing.ColorTranslator.FromHtml("#FF0000");
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(color);
MessageBox.Show("The PDF File is saved at the location of @“D:\test\output.pdf”);
catch(Exception ex)
//***Code End
linking-issue.pdf (103.7 KB)

Can you please look into this issue and Let me know is there issue in Aspose.PDF or Am I doing something incorrect her?
Please let me know if you need any more information on this. Immediate response is appreciable!


Thank you for contacting support.

We are unable to reproduce the issue with Aspose.PDF for .NET 19.4 with same code and sample PDF file. Generated PDF document has been attached for your kind reference Hyperlink_19.4.pdf. Moreover, you may visit Working with Links and Actions for your kind reference.