FreeBSD - Converting images to PDF (dealing with 'encrypted files')
Hi !
I recently had another request to make a single PDF file from some small PDF files.
I was confident because I already indicated in a previous post how to proceed with FreeBSD (https://www.openmon.org/blog/posts/post-2023031401/) but came across an unexpected scenario.
% pdfunite 1.pdf 2.pdf foo.pdf
Unimplemented Feature: Could not merge encrypted files ('2.pdf')
The first file is OK but the second seems to be encrypted…
Let’s see what this file is made of. To do this, install the ’exiftool’ utility which allows you to read and write meta information.
# pkg install p5-Image-ExifTool
Let’s run it on the faulty file.
% /usr/local/bin/exiftool 2.pdf
ExifTool Version Number : 12.50
File Name : 2.pdf
Directory : .
File Size : 102 kB
File Modification Date/Time : 2023:04:30 17:33:58-04:00
File Access Date/Time : 2023:05:01 17:59:59-04:00
File Inode Change Date/Time : 2023:04:30 17:46:16-04:00
File Permissions : -rw-r--r--
File Type : PDF
File Type Extension : pdf
MIME Type : application/pdf
PDF Version : 1.4
Linearized : No
Encryption : Standard V2.3 (128-bit)
User Access : Print, Copy, Extract, Print high-res
Page Count : 2
Creator : Demo Inc.
Title : Statement
Create Date : 2023:04:21 12:39:25-04:00
Producer : PDFlib+PDI 9.2.0 (JDK 1.8/Linux-x86_64)
We obviously need to try to remove the detected cipher. For this, we have the ‘qpdf’ utility but at first, we need to install it.
# pkg install qpdf
What are we talking about that software ?
% man qpdf
NAME
qpdf - PDF transformation software
SYNOPSIS
qpdf [ options ] infilename [ outfilename ]
DESCRIPTION
The qpdf program is used to convert one PDF file to another equivalent PDF file. It is capable of performing a variety of transformations such as linearization (also known as web optimization or fast web viewing), encryption, and decryption of PDF files.
How can we decipher something ?
% qpdf --help=all | grep decrypt
--decrypt: remove encryption from input file
Now it’s time to decrypt the file.
% qpdf --decrypt 2.pdf 2_no_encrypt.pdf
Let’s check it again with some help from ’exiftool’.
% /usr/local/bin/exiftool 2_no_encrypt.pdf
ExifTool Version Number : 12.50
File Name : 2_no_encrypt.pdf
Directory : .
File Size : 102 kB
File Modification Date/Time : 2023:05:01 18:04:35-04:00
File Access Date/Time : 2023:05:01 18:21:20-04:00
File Inode Change Date/Time : 2023:05:01 18:04:35-04:00
File Permissions : -rw-r--r--
File Type : PDF
File Type Extension : pdf
MIME Type : application/pdf
PDF Version : 1.4
Linearized : No
Create Date : 2023:04:21 12:39:25-04:00
Creator : Symcor Inc.
Producer : PDFlib+PDI 9.2.0 (JDK 1.8/Linux-x86_64)
Title : Statement
Page Count : 2
No more encryption. It’s time to try to concatenate the two files.
% pdfunite 1.pdf 2_no_encrypt.pdf foo.pdf
It seems to work (read: “I no longer have an error”).
Cheers.