Remove / Disable URL links in PDF

For our end client application, we need to disable hyperlink URLs in PDF documents.


I’m using this code without success:

com.aspose.pdf.Document document = new com.aspose.pdf.Document(“sample.pdf”);
document.setOpenAction(null);
document.save(“output.pdf”);

Any suggestions please?

Thank you in advance.


Hi Mouad,

Thanks for contacting support.

In order to accomplish your requirement, you may consider using the following code snippet.

In case you encounter any issue, please share the resource file so that we can test the conversion in our environment.

Java

//Load the PDF file
Document doc = new Document("c:/pdftest/Sample.pdf");

//Get the first link annotation from
//first page of document
LinkAnnotation linkAnnot =
(LinkAnnotation)doc.getPages().get_Item(1).getAnnotations().get_Item(1);

//flatten link address
linkAnnot.flatten();

// Save the document with updated
//link
//linkAnnot. .setAction(new
//com.aspose.pdf.GoToURIAction(" "));

doc.save("c:/pdftest/Sample_LinksRemoved.pdf");