1

I have an encrypted pdf, and I am aware of the password, and I would like to use the Ghostscript to make them unencrypted, so they don't require any password to be opened.

I tried using the following, But it seems I'm doing something wrong

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=OUTPUT.pdf -c .setpdfwrite -f -sUserPassword=mypassword encrypted.pdf

2 Answers2

3

If using a different tool like pdftk/qpdf first is an option, the answers to this question have a couple of methods, for example qpdf -password=mypassword -decrypt encrypted.pdf OUTPUT.pdf

1henno1
  • 51
2

If you have a pdf that is encrypted and you know the password you can decrypt the pdf as follows

gs -dNOPAUSE -dBATCH -q -sDEVICE=pdfwrite -sPDFPassword=password -sOutputFile=output2.pdf -f input.pdf

Now let me tell you about each option being used

  1. -sDEVICE: its a device, use man gs to learn more
  2. -dNOPAUSE: Disables the prompt and pause at the end of each page. This may be desirable for applications where another program is driving Ghostscript.
  3. -q: do things quietly, no logs on screen
  4. -sPDFPassword: Its the password
  5. -dBATCH: I think it is for quitting the gs

Like every Linux Program, the Documentation (man pages) is written very poorly and doesn't have a lot of information.

  • 1
    This method works well, but it does so by "printing" the PDF to a new PDF. So you lose any fancy things like forms or interactivity. Sometimes this is what you want though. The other qpdf answer leaves these interactive elements in place if you prefer to keep them. – Malvineous Dec 24 '22 at 10:42