DEV Community

loading...

Merging images/PDF to create a new wholesome PDF file

patarapolw profile image Pacharapol Withayasakpunt ・1 min read

I came across that I have to fix a lot of images, and sometimes multiple of PDF files each has only one page.

Tools here are in Ubuntu Linux; in Windows, it should be accessible via WSL; not sure about macOS.

sudo apt install imagemagick poppler-utils
Enter fullscreen mode Exit fullscreen mode

Then you now have two important commands - convert and pdfunite.

Now, I have another important problem - ImageMagick security policy 'PDF' blocking conversion

Though, my solution is

sudo nano /etc/ImageMagick-6/policy.xml
Enter fullscreen mode Exit fullscreen mode

To issue commands, for some reasons, convert supports wildcards, but not pdfunite.

convert "$FOLDER_NAME/*.GIF" "$FOLDER_NAME.pdf"
pdfunite x/x1.pdf x/x2.pdf x/x3.pdf x.pdf
Enter fullscreen mode Exit fullscreen mode

Lastly, this post is possible because of

code ~/.zsh_history
Enter fullscreen mode Exit fullscreen mode

Discussion

pic
Editor guide