Hello,
We have purchased Aspose.PDF license and implementing pdf functionality in one of our project. As per our requirement we need to change link annotation color to red for specific text in the document. After going through one of your reference we have implemented the functionality. But the color is changing for some text in one page but not in another page for same document.
Here is the code we are using.
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense("Aspose.Pdf.lic");
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(filePath);
int noofpages1 = 0;
noofpages1 = doc.Pages.Count;
for (int p = 1; p <= noofpages1; p++)
{
Aspose.Pdf.Page page = doc.Pages[p];
AnnotationSelector selector = new AnnotationSelector(new Aspose.Pdf.InteractiveFeatures.Annotations.LinkAnnotation(page, Aspose.Pdf.Rectangle.Trivial));
int height72Dpi = 792;
page.Accept(selector);
IList list = selector.Selected;
if (list.Count > 0)
{
foreach (LinkAnnotation a in list)
{
try
{
Aspose.Pdf.InteractiveFeatures.Annotations.Border border = new Aspose.Pdf.InteractiveFeatures.Annotations.Border(a);
//llx = Convert.ToInt32(a.Rect.LLX);
//urx = Convert.ToInt32(a.Rect.URX);
//lly = Convert.ToInt32(height72Dpi - a.Rect.LLY);
//ury = Convert.ToInt32(height72Dpi - a.Rect.URY);
//Aspose.Pdf.InteractiveFeatures.Annotations.LinkAnnotation link = new Aspose.Pdf.InteractiveFeatures.Annotations.LinkAnnotation(page, new Aspose.Pdf.Rectangle(llx, height72Dpi - lly, urx, height72Dpi - ury));
TextFragmentAbsorber ta = new TextFragmentAbsorber();
Aspose.Pdf.Rectangle rect = a.Rect;
rect.LLX -= 10;
rect.LLY -= 10;
rect.URX += 10;
rect.URY += 10;
ta.TextSearchOptions = new TextSearchOptions(rect);
ta.Visit(doc.Pages[p]);
// Change color of the text.
foreach (TextFragment tf in ta.TextFragments)
{
tf.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red);
border.Width = 0;
}
//}
}
catch (Exception exp)
{
}
}
}
}
doc.Save(filePath);
These are the scenarios we have tested.
1) The attachment document "bookmarks.pdf" contains some links with blue color which we wanted to change the color to red. But it is not happening.
2)The document "DVI-7310_Data.PDF" first page right side cornor text "DVI-7310" is getting updated with red color but remaining text "Single-Link DVI Fiber Optic Extender" is not getting updated. We have made some other links also on the same page those are working fine.
Could you please let us know the resolution for this problem.