Page 1 of 1

Merging PDF Files

Posted: 2007-01-03T10:16:33-07:00
by tome100
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.

Posted: 2007-01-03T19:04:03-07:00
by anthony
This is a BAD idea.

See IM Examples... A word about Vector Image formats
http://www.cit.gu.edu.au/~anthony/graph ... ts/#vector

Posted: 2007-01-04T08:50:31-07:00
by tome100
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.

Posted: 2007-01-04T09:04:02-07:00
by redace
tome100 wrote: 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.

Posted: 2007-01-04T12:33:50-07:00
by tome100
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.

Posted: 2007-01-04T14:23:38-07:00
by oddball508
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.

Posted: 2007-01-04T15:14:07-07:00
by pbender
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.

Paul

Posted: 2007-01-04T15:54:23-07:00
by tome100
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.

Posted: 2007-01-04T16:00:45-07:00
by magick
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.

Posted: 2007-01-04T17:45:29-07:00
by anthony
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...

Posted: 2007-01-05T11:59:19-07:00
by nileshp
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..
exec('convert')
vs.
exec('/usr/bin/convert')