Merging PDF Files

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
tome100

Merging PDF Files

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
tome100

Post 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.
redace

Post 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.
tome100

Post 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.
oddball508

Post 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.
pbender

Post 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
tome100

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post 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...
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
nileshp

Post 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')
Post Reply