DEV Community

Pacharapol Withayasakpunt
Pacharapol Withayasakpunt

Posted on

2

Merging images/PDF to create a new wholesome PDF file

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

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay