PDF Cheatsheet
As with all of my cheatsheets, this is just a dumping ground for as things come up.
Save Unlocked PDF
If you get a PDF that requires a password to unlock, you can use this command to save a version that won't need unlocking in future.
qpdf \
--password=$PASSWORD \
--decrypt $INPUT.pdf \
$OUTPUT.pdf
sudo apt-get install qpdf
.
Create A PDF From A Series Of Images
The following command will create a PDF document where all the images are the same width.
convert -quality 100% -resize 629 \
"path/to/image.png" -resize 629 \
"path/to/image2.png" -resize 629 \
output.pdf
-resize 629
. Also, all your images need to have the same DPI, otherwise it doesn't work.
Fixing Error Message
If you get the error message:
convert-im6.q16: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408.
Then do the following. Edit your ImageMagick policy configuration:
editor /etc/ImageMagick-6/policy.xml
Add the following just before the final </policy>
tag:
<policy domain="coder" rights="read | write" pattern="PDF" />
E.g.
<policy domain="coder" rights="none" pattern="PDF" />
<policy domain="coder" rights="none" pattern="XPS" />
<policy domain="coder" rights="read | write" pattern="PDF" />
</policymap>
It should now work!
Convert PDF To Set Of Images
Tools like Figma make it really easy to export as a single PDF. However, I need to convert that to just a set of PNG images. Luckily this is really easy, and essentially the same as before in reverse (using ImageMagick).
convert \
input-file.pdf \
output.png
That will create a set of incremented filenames like so:
- output-0.png
- output-1.png
- output-2.png
References
- How-To Geek - How to Remove a Password from a PDF File in Linux
- Stack Overflow - ImageMagick security policy 'PDF' blocking conversion
First published: 14th April 2019