Site Overlay

Fix for increased file size when removing a PDF password on Mac OS

Over the last couple of months I received some password protected PDF files. While using this kind of protection is easy for casual users, I find it kinda annoying that it forces me to add a separate step to my process when storing these files without a password on my local disk. And here I noticed some quirks when doing that step on Mac OS.

The easiest way to remove the password is clearly to use the Preview application, and to export / save the document as a new file after supplying the required password. Doing that the problem is that in some cases the file size of the resulting PDF file is increasing, and that not only marginal but can reach easily up to 5 times the original size:

henrik  staff   241184 Nov 24 19:54 example_with_password.pdf
henrik  staff  1235761 Nov 24 19:54 example_exported.pdf

Given that it should be a loss-less operation it’s unclear what Preview is actually processing here. Also using the Reduce File Size Quartz filter within the save dialog doesn’t help at all. The file size stays equal to the exported document.

Also interesting is that printing the document again as PDF is even worse:

henrik  staff  1257992 Nov 24 19:54 example_printed.pdf

As such I’m not going to use that particular path to remove the password from the PDF file because having a lot o those files clearly impacts the disk space usage.

So the question now is which alternatives exist? I played around a bit…

Firefox‘s internal PDF viewer is not able to remove a password, but allows me to just print the document again. I tried that method to check if there is a difference to Preview’s print functionality. I didn’t expect one because printing the document is handed over to the operating system. But surprisingly I saw that:

henrik  staff   686430 Nov 24 19:54 example_firefox.pdf

What? The size has been nearly divided in half, and now is only ~3x that large as the original file without any loss of quality. How can this be? Hard to tell without closely inspecting the PDF file for which I don’t have the time. So I suspect that there might be a possible bug in Preview.

While searching for other solutions I stumbled over a command line tool qdpf that describes itself as:

QPDF is a command-line program that does structural, content-preserving transformations on PDF files.

That sounds promising given that this is exactly what I want to have. Just decrypting the file and leaving everything as is. And even better it’s a command line program, so that I can perfectly embed it into my workflow. To install it you will have to get Homebrew (or MacPorts) first. After the installation run the following command to decrypt the file by supplying a password:

qpdf --decrypt --password=test example.pdf example_qpdf.pdf

And finally that perfectly results in a PDF file with just the password removed. And as bonus point it even reduced the file size a bit:

henrik  staff   240209 Nov 24 19:54 example_qpdf.pdf

As conclusion I can say that it’s always good to not only check the result of an operation, but also having a look for any possible side-effects. Sometimes it might not be that obvious as with the file size and harder to spot, but once seen the Internet is a pretty good resource to get problems resolved.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.