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.
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.