Page 1 of 1
Merging PDF Files
I am trying to merge PDF files with imagemagick by means of convert. This works fine when I run the command direct from SSH, but when I run the exact same command from PHP, it doesn't work. Another thing is that the exec("convert string", $returnvar); $returnvar never returns anything even if it doesn't / does work. I know that imagemagick is installed and working with PHP, cause I can convert TIF's to PDF's and even merge multiple tifs to pdfs. I just cant merge multiple pdfs into one.
This is a BAD idea.
See IM Examples... A word about Vector Image formats
http://www.cit.gu.edu.au/~anthony/graph ... ts/#vector
Regaurdless, I still need to merge the PDF files. I know the merging works fine. I am converting TIF's to PDF's, then allowing them to merge PDF's for easy viewing. "Bad" idea or not, I still need it to work. And it works fine from SSH, but wont work in PHP.
Regaurdless, I still need to merge the PDF files.
You need somthing that works directly on vector files, since Imagmagick rasterizes PDFs before working with them.
A quick google reveals tools such as http://www.accesspdf.com/pdftk/
. You might want to try that route.
Another route would be to merge the seperate tif files into one multipage tif, then saving as PDF.
The problem is not imagemagick. I was looking at the log files, and it appears when the "apache" user attempts to convert, it doesn't have access to ghostscript. ("gs: command not found") Any idea why? Ghostscript is installed and works from SSH as "root" user.
Having done a lot of PDF merges in recent time (1,500,000 single page pdf files into 17,800 combined files) I found that the about PDFTK was the best. Unlike ImageMagick when you combine PDF files it does not rerender the images (which leads to image quality loss).
I do you ImageMagick and Ghostscript for every other PDF and image file processing.
I never thought to use imagemagick for this.
I use Ghostscript directly to merge postscript and PDF files.
The command line I typically use (on a linux box) is of the form:
Code: Select all
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=Merged.pdf -dBATCH 1.ps 2.pdf 3.pdf
You can mix and match postscript and pdf files for the inputs.
I've tried the command line, pdftk, and imagemagick. The problem is that for some reason the user "apache" returns an error: sh: gs: command not found
However when I run it from the command line (as root), it works fine.
You must either ensure that gs is in the apache execution path and has proper permissions or edit delegates.xml and ensure gs has an absolute path such as /usr/local/bin/gs.
You could also try to set the 'PATH' environment yourself in the PHP. Though this is better done by the sys-admins in the the web server start up script.
This is also the best way for doing IM commandline calls from PHP.
However many Sys-admins will not do this as they don't know enough about web apps, and may consider such a request a security hole. Note that it is, as it is, as the apps can make the calls anyway! It just locks the web apps to specific machine setups. Arrrgghhh...
I had some what of same issue.
my problem was that server has more then one version of imagemagick installed..
so when doing convert from ssh vs command line (Web) it calling up two differnt version.
to narrow down the issue i did was exec('convert -version') on the web to track down that SSH version is newest vs teh exec that ran a older version.
so if you analize the output of the exec version and compare it to ssh version #?
so i had to use a full path when calling it from exec() function..
solution for example..