Home » Blog » Converting and Joining pdf Files in MacOS

Converting and Joining pdf Files in MacOS

— Created: Xiaoke, 2017/05/16 14:38 CST
— Last modified: Xiaoke, 2017/05/16 16:03 CST

A GUI Approach

The Preview app is very handy if you only have a couple of files to convert and merge. Through 'Export as PDF', images can be conveniently converted into pdf files. By showing the Thumbnails and dragging, pdf files can be easily merged. The order of the pages can also be changed in this way.

However, I'll give a command-line alternative to this in order to handle larger number of files.

Convert images to pdf files

The convert program in the ImageMagick software suit is used (use brew install imagemagick to install ImageMagick). A for loop can be executed if there are too many files, such as

for i in `ls *.jpeg`; do echo $i; fn=`echo $i | sed -e 's/jpeg/pdf/g'`; echo $fn; convert -resize 100% $i $fn; done

the -resize option is to change the size of the generated pdf.

Merge pdf files

pdfunite is a program coming with the Poppler pdf rendering library, which can be installed by brew install poppler. Having no options other than the help message and version information, this program is super-easy to use. Basically, you just throw in all the input files and append an output file name at the end of the command line, as

pdfunite in1.pdf in2.pdf in3.pdf out.pdf; 
pdfunite *.pdf out.pdf