Wednesday, September 23, 2015

Use Imagemagick to combine merge multiple PDF files into one single file

Use Imagemagick to combine merge multiple PDF files into one single file

Install ImageMagick:

# yum install gcc php-devel php-pear
# yum install ImageMagick ImageMagick-devel

Install ImageMagick PHP Extension:

# pecl install imagick

Merging multiple PDF files into one file:

# convert -density 150 *.pdf output.pdf

Troubleshoot:

convert.exe: FailedToExecuteCommand `"gswin32c.exe" -q -dQUIET -dSAFER -dBATCH -
dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEV
ICE=pamcmyk32" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -dUseCIEColor
"-sOutputFile=C:/Users/MDOLAN~1.COR/AppData/Local/Temp/magick-3704HYGOqqIK5rhI%d
" "-fC:/Users/MDOLAN~1.COR/AppData/Local/Temp/magick-3704vK6aHo7Ju9WO" "-fC:/Use
rs/MDOLAN~1.COR/AppData/Local/Temp/magick-3704GQSF9kK8WAw6"' (The system cannot
find the file specified.
) @ error/delegate.c/ExternalDelegateCommand/480.
convert.exe: PDFDelegateFailed `The system cannot find the file specified.
' @ error/pdf.c/ReadPDFImage/797.
convert.exe: no images defined `a.jpg' @ error/convert.c/ConvertImageCommand/323
0.

You need to install Ghostscript in order to rasterize vector files (PDF, EPS, PS, etc.) with ImageMagick. IM will shell out to Ghostscript when doing these manipulations (you can see it if you use the -verbose tag in your IM invocation). You could also use Ghostscript by itself to rasterize vector files.

Reference:

http://www.imagemagick.org/script/index.php
http://tecadmin.net/install-imagemagick-on-linux/
http://stackoverflow.com/questions/32466112/imagemagick-convert-pdf-to-jpeg

No comments: