47

I have several PDF documents which have the "no copy" and "no print" restriction bits set. Are there any free tools for removing such restrictions, on Linux?

I tried pdf2ps | ps2pdf but the size increase is horrible. The originals are fairly large too, so I'd rather use a local tool than a website.

jww
  • 11,918
  • 44
  • 119
  • 208
u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • Willing to write any code or are you wanting something out of the box? – Aaron McIver Dec 12 '11 at 15:08
  • Code is okay, although I have a feeling it'll be C, and my C skills are limited to "Hello world". – u1686_grawity Dec 12 '11 at 15:13
  • 1
    You could use iText; http://itextpdf.com/itext.php this can be done in Java. – Aaron McIver Dec 12 '11 at 15:30
  • 3
    possible duplicate of [How to remove security from a PDF file?](http://superuser.com/questions/179064/how-to-remove-security-from-a-pdf-file) and/or [How to remove a .pdf's document restrictions?](http://superuser.com/questions/210686/how-to-remove-a-pdfs-document-restrictions) also perhaps see: [Removing the password from a PDF file](http://superuser.com/questions/86266/removing-the-password-from-a-pdf-file) – Ƭᴇcʜιᴇ007 Dec 12 '11 at 16:33

4 Answers4

101

With qpdf:

$ qpdf --decrypt restricted-input.pdf unrestricted-output.pdf
tokland
  • 1,230
  • 1
  • 9
  • 11
37

You can probably use pdftk. Something like

pdftk in.pdf output out.pdf allow AllFeatures

should do the job.

Sathyajith Bhat
  • 61,504
  • 38
  • 179
  • 264
u-punkt
  • 546
  • 3
  • 4
  • 3
    This would work if the password is known. – Scott McClenning Dec 13 '11 at 02:39
  • 7
    I'm probably a few years late, but the owner password does not have to be known for this, just the user password, if there's any. It warns you not to abuse the power to simply remove the owner password and the limitations altogether, but does it without further complaining. I think this should be the accepted answer. – matega Dec 10 '14 at 08:04
  • 1
    For whom it may concern, `pdftk` is written in java and requires JRE. – logicor Jul 19 '21 at 02:56
  • 1
    Thanks so much. I needed to OCR an Intel datasheet from the 80's, and `ocrmypdf` refused to run until I'd done this. `pdftk` works (at least the version in Debian). – Wyatt Ward May 06 '22 at 19:04
20

If you've got ghostscript installed try simply:

gs -sPDFPassword=$PASS -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=%stdout% -c .setpdfwrite -f locked.pdf > unlocked.pdf
thebodzio
  • 510
  • 2
  • 10
  • 5
    +1 and [found a variation online](http://www.cyberciti.biz/faq/removing-password-from-pdf-on-linux/#comment-45548): `gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=unencrypted.pdf -c .setpdfwrite -f encrypted.pdf`. Worked for me in a few seconds, faster than brute-forcing a password... – bufh Jul 09 '16 at 15:51
  • 1
    Side note, in my case the original file was 10 MB, after [`gs`](http://www.ghostscript.com/) it was 3.7 MB. – bufh Jul 09 '16 at 16:01
  • 3
    @bufh It probably reduced the resolution. GhostScript defaults to something like 72 dpi unless you specify an alternative with something like `-r` (eg. `-r300`). Also, make sure you pass `-dSAFER`. PostScript is a turing-complete programming language and, last I checked, GhostScript's default was to allow arbitrary filesystem access. – ssokolow Jan 17 '17 at 00:44
4

FOSS-wise, there is PDFCrack, not sure if it does actually remove the security though, it's just a password cracker. I generally turn to some free trial software, A-PDF Restrictions Remover, it's easier to use.

It might be a lot harder if it's a recent PDF version though, I think they really increased the security recently.

Hydaral
  • 1,722
  • 9
  • 11
  • Ended up buying the A-PDF tool. – u1686_grawity Jun 22 '15 at 10:07
  • A-PDF tool wants to make changes to the computer. Why does a PDF editor need to change the machine's configuration? It is a classic violation of least privilege and is probably laced with malware. – jww Jun 07 '18 at 19:01