vardomskiy (vardomskiy) wrote,
vardomskiy
vardomskiy

Decrypting PDFs using GhostScript

For what it's worth, you can use GhostScript to convert encrypted PDFs that have owner password set (but do not have open password set) to unencrypted PDFs using the following command line:

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=unencrypted.pdf -c .setpdfwrite -f encrypted.pdf


It's quite slow (since each object gets decrypted separately), but it works. One of the side-effects is that the unencrypted PDF file gets quite a bit larger in size. At this point you can use pdftk to even further decompress the file (and actually be able to do some editing of the data) using

pdftk  unencrypted.pdf  output unencrypted_uncompressed.pdf uncompress


Once editing is done, recompress thusly:
pdftk unencrypted_uncompressed.pdf output unencrypted_recompressed.pdf compress



Writing a batch file, such as

for ii in *pdf ; do gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=unencrypted.${ii} -c .setpdfwrite -f ${ii} ; done


is left as an exercise to the reader.

Next, of course, is the fun of removing watermarks from PDF files :-) Some of that can be done by editing uncompressed and unencrypted file, but alot of it is a pain in the behind to do.
Tags: fuckyou
Subscribe

  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 1 comment