Removing PDF usage restrictions

33

18

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.

user1686

Posted 2011-12-12T15:05:20.650

Reputation: 283 655

Question was closed 2018-06-11T05:53:00.760

Willing to write any code or are you wanting something out of the box? – Aaron McIver – 2011-12-12T15:08:34.807

Code is okay, although I have a feeling it'll be C, and my C skills are limited to "Hello world". – user1686 – 2011-12-12T15:13:00.197

1

You could use iText; http://itextpdf.com/itext.php this can be done in Java.

– Aaron McIver – 2011-12-12T15:30:33.910

3

possible duplicate of How to remove security from a PDF file? and/or How to remove a .pdf's document restrictions? also perhaps see: Removing the password from a PDF file

– Ƭᴇcʜιᴇ007 – 2011-12-12T16:33:41.830

Answers

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

Posted 2011-12-12T15:05:20.650

Reputation: 1 674

Ended up buying the A-PDF tool. – user1686 – 2015-06-22T10:07:26.220

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 – 2018-06-07T19:01:21.620

66

With qpdf:

$ qpdf --decrypt restricted-input.pdf unrestricted-output.pdf

tokland

Posted 2011-12-12T15:05:20.650

Reputation: 880

3qpdf works very well. There is a convenient pre-built Windows binary, which is a plus. – Li-aung Yip – 2015-03-19T04:04:29.347

This only works if you know the current password – iamkhush – 2019-09-15T08:33:04.017

@iamkhush This requires the password if the file is actually encrypted and requires a password for opening, but it removes the no-print/no-copy DRM just fine without. – kinokijuf – 2020-02-01T19:42:44.173

29

You can probably use pdftk. Something like

pdftk in.pdf output out.pdf allow AllFeatures

should do the job.

u-punkt

Posted 2011-12-12T15:05:20.650

Reputation: 466

5I'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 – 2014-12-10T08:04:33.603

3This would work if the password is known. – Scott McClenning – 2011-12-13T02:39:24.310

17

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

Posted 2011-12-12T15:05:20.650

Reputation: 430

1

+1 and found a variation online: 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 – 2016-07-09T15:51:11.497

Side note, in my case the original file was 10 MB, after gs it was 3.7 MB.

– bufh – 2016-07-09T16:01:03.267

1@bufh It probably reduced the resolution. GhostScript defaults to something like 72 dpi unless you specify an alternative with something like -r<dpi> (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 – 2017-01-17T00:44:13.860