Articles in this section
Category / Section

How to remove hyperlinks from the existing PDF document?

1 min read

How to remove hyperlinks from the existing PDF document?

The hyperlinks can be removed from the existing PDF document by removing the URI and document link annotations from the document. Please refer the below code snippet and sample for the same.

C#

//Load the file
PdfLoadedDocument lDoc = new PdfLoadedDocument(@"input.pdf");
 
for (int i = 0; i < lDoc.Pages.Count; i++)
{
//Get the annotation collection
PdfAnnotationCollection annotColl = lDoc.Pages[i].Annotations as PdfLoadedAnnotationCollection;
 
for (int j = 0; j < annotColl.Count; j++)
{
//Get the annotation
PdfLoadedAnnotation annot = annotColl[j] as PdfLoadedAnnotation;
 
 
if (annot is PdfLoadedTextWebLinkAnnotation || annot is PdfLoadedUriAnnotation)
{
//Remove the hyperlinks
annotColl.Remove(annot);
}
}
}
//Save and close the document
lDoc.Save(@"sample.pdf");
lDoc.Close(true);

 

Sample link:

https://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfSample-181943694

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied