Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDF - Programmatically remove hyperlinks using Ghostscript

I have a PDF document which has hyperlinks at the bottom of each page. Last week I successfully removed them using the trial version of Adobe Acrobat X Pro on Windows, however since then I've mislaid the new document and I've installed Ubuntu 14.04. Is there a way I can programmatically do a (Tools > Edit Tool > Delete) action as I did on Windows using something like Ghostscript? I don't want to reinstall Windows, but I will if there's no alternative.

like image 627
user1408643 Avatar asked Nov 01 '22 22:11

user1408643


2 Answers

As for this answer on TexExchange, discarding hyperlinks in PDFs is actually the default in ghostscript. So simply running it like this will do the trick:

gs -sDEVICE=pdfwrite                \
   -dCompatibilityLevel=1.4         \
   -dPDFSETTINGS=/prepress          \
   -dNOPAUSE -dQUIET -dBATCH        \
   -sOutputFile=output.pdf          \
    input.pdf

You would need to set the option "-dPrinted=false" in order for ghostscript to leave hyperlinks in the output PDF.

like image 51
suluke Avatar answered Nov 18 '22 23:11

suluke


Using gs 9.27, apparently the default behaviour changed, i needed

-dPreserveAnnots=false

to remove hyperlinks.

Source: https://www.ghostscript.com/doc/current/VectorDevices.htm

like image 28
connectedMind Avatar answered Nov 18 '22 23:11

connectedMind