Dear Team
I am not able to remove hyperlinks for some of documents. For some other documents it is working fine. Please find code and sample input file and output file generated. Please suggest a resolution.
Regards
Raj
remove hyperlink.zip (11.4 KB)
@crshekharam
Thank you for contacting support.
Please update your code as under where we have overridden default link by LinkAnnotation
configured with empty GoToAction
.
public static void RemoveHyperlinks(String FileIn, String FileOut)
{
Document doc = new Document(FileIn);
foreach (Aspose.Pdf.Page page in doc.Pages)
{
AnnotationSelector selector = new AnnotationSelector(new Aspose.Pdf.Annotations.LinkAnnotation(page, Aspose.Pdf.Rectangle.Trivial));
page.Accept(selector);
IList<Annotation> list = selector.Selected;
foreach (LinkAnnotation a in list)
{
if (a.Action != null && a.Action.GetType() == typeof(Aspose.Pdf.Annotations.GoToURIAction))
{
LinkAnnotation linkAnnot = new LinkAnnotation(page, a.Rect);
linkAnnot.Border = new Border(linkAnnot);
linkAnnot.Border.Width = 0;
page.Annotations.Add(linkAnnot);
}
}
}
doc.Save(FileOut);
}
We hope this will be helpful. Please feel free to contact us if you need any further assistance.
This solution removed link. However still the hand symbol is shown when we place cursor over the text indicating that it is a link.
@crshekharam
Thank you for your kind feedback.
Well, it is probably the PDF viewer which displays it as hyperlink, so the API may not change this. Please let us know if you are able to remove hyperlink while converting it to plain text with Adobe Acrobat because Aspose.PDF API mimics the behavior of aforementioned application.