The PDF file format is very complex and contains many features to boost interactivity. One such feature is the ability for PDF files to contain links to external web pages or other resources.
While useful, this functionality introduces risks! Bad actors can embed malicious hyperlinks which can be a source of phishing or cross-site scripting (XSS) attacks.
Our PDF toolkit JPedal allows you to remove links from PDF documents and sanitize files, removing the risk of malicious links.
To do this you need to download a JPedal jar, then run the following code:
final PdfManipulator pdf = new PdfManipulator();
pdf.loadDocument(new File("inputFile.pdf"));
pdf.removeLinks();
pdf.apply();
pdf.writeDocument(new File("outputFile.pdf"));
pdf.closeDocument();
Additionally, you may want to consider other sanitization options to secure your documents.
Resources
You can download a trial jar from our website.
Learn more about the PDF Manipulator API.
We can help you better understand the PDF format as developers who have been working with the format for more than 2 decades!