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

2

30

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.

Baptlsta answered 8/7, 2020 at 13:11 Comment(0)
P
35

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.

Pinkie answered 24/8, 2021 at 1:11 Comment(1)
I had to do this to all the files I wanted to merge, xargs to the rescue: ls *.pdf | xargs -I '{}' qpdf --decrypt {} --replace-inputErase
T
11

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.

Tourist answered 15/7, 2020 at 1:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.