'poppler pdfunite cannot merge encrypted PDF files, how to remove encryption? (no password needed to open)

I have some PDF files which I want to merge into one. I typically use pdfunite from the Poppler PDF toolkit to do this.

However now I'm getting this error:

Could not merge encrypted files ('foo.pdf')

When I run exiftool foo.pdf to see its properties, it does mention this:

Encryption : Standard V1.2 (40-bit)

I don't fully understand how encryption in PDF files work or what it's supposed to do, but I can open and read this particular file without entering any password. I can open the file in macOS Preview, no problem. I can convert the PDF into a PNG image using Poppler's own pdftoppm tool, no problem.

How do I override or remove this encryption, so I can merge this PDF file with other PDFs using Poppler's pdfunite ?

In case this encryption is just a metadata property, I already tried removing all metadata using exiftool like this:

exiftool -all= -overwrite_original foo.pdf

And exiftool has no problem removing the metadata. But the resulting file is still encrypted and pdfunite can't process it.



Solution 1:[1]

In order to prepare files reported as encrypted for pdfunite, install the qpdf utility and run the following command:

qpdf --decrypt "in.pdf" "out.pdf"

or qpdf --decrypt "in.pdf" --replace-input to overwrite the original file, which appeared safe to do during my experiments.

Then, the files can be merged using pdfunite as usual.

Solution 2:[2]

I have had the same problem with PDFv1.6 files. I was able to resolve by downgrading to PDFv1.4 using: "gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -o output.pdf input.pdf". As described in https://superuser.com/questions/184288/how-to-convert-a-pdf-document-to-an-older-version .

I had been using pdfunite to combine files at different PDF versions and think the PDFv1.6 file had some kind of signature in it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2