Score:1

How do I remove password from a PDF using ghostscript, when password is known?

jp flag

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
Score:2
jp flag

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.

jp flag
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.
Score:2
cg flag

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

Bruno Martinez avatar
in flag
qpdf didn't bloat the output pdf like gs
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.