When we create link with text color change, the text of other than link area is being Changed and Erased. We are replicated this in AsposePDF v19.4.0.0(this issue exits in AsposePDF v18.10.0.0 also)
Please see the attached “before.pdf”(before creating the link the pdf like this) and “after.pdf”(after creating the link the pdf changed to).
after.pdf (129.1 KB)
before.pdf (133.1 KB)
I used following code to create link with text color change using Aspose.PDF v19.4.0.0
//***Code Start
try
{
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.Embedded = true;
license.SetLicense(“Aspose.Pdf.lic”);
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;
page.Annotations.Add(link);
foreach (Annotation annotation in page.Annotations)
{
if (annotation is LinkAnnotation)
{
Aspose.Pdf.Rectangle rect = annotation.Rect;
TextFragmentAbsorber absorber = new TextFragmentAbsorber();
absorber.TextSearchOptions.Rectangle = rect;
page.Accept(absorber);
foreach (TextFragment textFragment in absorber.TextFragments)
{
System.Drawing.Color color = System.Drawing.ColorTranslator.FromHtml("#FF0000");
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(color);
}
}
}
pdf.Save(@“D:\test\after.pdf”);
MessageBox.Show("The PDF File is saved at the location of @“D:\test\after.pdf”);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
//***Code End
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!