PDF joining limited to 14 files... convert: Postscript delegate failed

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Post Reply
boognish100
Posts: 14
Joined: 2016-09-14T00:19:26-07:00
Authentication code: 1151

PDF joining limited to 14 files... convert: Postscript delegate failed

Post by boognish100 » 2017-09-22T18:37:50-07:00

I have a PHP script which uses ImageMagick to join PDF's, this work well up to a point.

Code: Select all

function show_Names($e) { return "/home/me/public_html/temp/".$e['pdffilename'].".pdf "; }
$c = array_map("show_Names", $_POST['item']);
exec("convert -density 300 ".implode(' ', $c)."/home/me/public_html/temp/latest.pdf", $array);
However beyond joining 14 PDF files I get errors every time (error is ... convert: Postscript delegate failed), the pdf join is always limited to 14 PDF's, no matter what pdf files selected, the PDF files exist in the correct location and are not corrupted. The outputted joined PDF file only ever has 14 of the joined files. I've tried uninstalling ghostscript and ImageMagick and reinstalling via SSH but the issue persists. I've tried the script on three separate servers and get the same result. Troubleshooting with my hosting provider they said the server resources were not stretched during the operation and they believe the issue lies with ImageMagick.

How do I resolve this? Or are there alternate methods to join pdf's using ImageMagick which don't have issues of limits?

Below is the relevant snippet of conversation I had with the hosting provider...
Client: how do I uninstall/reinstall 'Ghostscript' via SSH?
Hosting: yum remove ghostscript ... Now did that also remove ImageMagick?
Client: ok removed
Hosting: then ... yum install ghostscript ... once that is finished...yum install ImageMagick
Client: ok done
Hosting: Then restart server. This should handle whatever issue you are encountering...Is there anything else I can do for you today?

Client: I get the following error when I try to join more than 14 pdf's...

[Fri Sep 22 20:30:37.154256 2017] [:error] [pid 24561] [client 49.228.229.55:28442] convert: Postscript delegate failed `/home/me/public_html/temp/59c2a820e96bc.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/664., referer: ****
[Fri Sep 22 20:30:37.148379 2017] [:error] [pid 24561] [client 49.228.229.55:28442] convert: Postscript delegate failed `/home/me/public_html/temp/59c584bad4a7f.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/664, referer: *****

So here I tried to join 16 pdfs, but the final 2 pdf's gives the above error on those pdfs. Those files 100% exist and are not corrupted. No matter which PDF's I select to join, any pdf's selected beyond 14 always get the above error on them, every time. Is this a limit of the server resources?

Hosting: Looking over, it looks like this is a problem with the program itself, not really the server. I'm not seeing anything we can do on our end, I would contact the creator of the program and seek support.
Client: Just to confirm, the resources of the server were not stretched during the pdf join operation a few minutes ago ie, memory, hard drive space, cpu limits?
Ryan S: Not that I can see on my end.
Client: Thanks, will go to their support forum with info

snibgo
Posts: 9379
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: PDF joining limited to 14 files... convert: Postscript delegate failed

Post by snibgo » 2017-09-22T19:37:32-07:00

What version ImageMagick? How large was each PDF? (How many pixels?)

I created 100 PDF files, then used IM v6.9.5-3 [EDIT with GS v9.19] to read them all in and create a single multi-image TFF file. It worked with no problem.

If you simply want to join PDFs together, pdfunite is probably a better tool for that job.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 22081
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: PDF joining limited to 14 files... convert: Postscript delegate failed

Post by fmw42 » 2017-09-22T19:47:37-07:00

What about your Imagemagick policy.xml file? Does it have enough resources? Is your Ghostscript up to date? You do not mention the GS version.

boognish100
Posts: 14
Joined: 2016-09-14T00:19:26-07:00
Authentication code: 1151

Re: PDF joining limited to 14 files... convert: Postscript delegate failed

Post by boognish100 » 2017-09-22T20:02:35-07:00

Ghostscript is 8.70
IM is 6.7.2.7-6
Each PDF is give or take 170KB
Pixels w * h is 2433 * 2904, 300dpi

How do I find/edit policy.xml amd determine if it has enough resources?

Thanks!

boognish100
Posts: 14
Joined: 2016-09-14T00:19:26-07:00
Authentication code: 1151

Re: PDF joining limited to 14 files... convert: Postscript delegate failed

Post by boognish100 » 2017-09-22T20:36:48-07:00

Now have new code using only GS, works great, no limit issue...

Code: Select all

function show_Names($e)
{
return "/home/me/public_html/temp/".$e['pdffilename'].".pdf ";
}
$fileArray = array_map("show_Names", $_POST['item']);
$datadir = "/home/me/public_html/temp/";
$outputName = $datadir."Latest.pdf";
$cmd = "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$outputName ";
foreach($fileArray as $file) {
    $cmd .= $file." ";
}
$result = shell_exec($cmd);

User avatar
fmw42
Posts: 22081
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: PDF joining limited to 14 files... convert: Postscript delegate failed

Post by fmw42 » 2017-09-22T23:14:13-07:00

Ghostscript is 8.70
IM is 6.7.2.7-6
These are both ancient release.

IM is at 6.9.9.14. (so over 250 versions old) (unless there have been patches).

My GS is

gs --version
9.21

You probably exceeded one of the policy.xml limitation (perhaps tmp space). But you can edit the policy.xml file (or your hosting provider can do that, if they are willing). See the link at http://www.imagemagick.org/script/resources.php to policy.xml

boognish100
Posts: 14
Joined: 2016-09-14T00:19:26-07:00
Authentication code: 1151

Re: PDF joining limited to 14 files... convert: Postscript delegate failed

Post by boognish100 » 2017-09-23T03:37:02-07:00

Good to know, will update both, thanks!

Cheers for the link will take a look

boognish100
Posts: 14
Joined: 2016-09-14T00:19:26-07:00
Authentication code: 1151

Re: PDF joining limited to 14 files... convert: Postscript delegate failed

Post by boognish100 » 2017-11-13T23:25:59-07:00

Code: Select all

function show_Names($e)
{
return "/home/me/public_html/temp/".$e['pdffilename'].".pdf ";
}
$fileArray = array_map("show_Names", $_POST['item']);
$datadir = "/home/me/public_html/temp/";
$outputName = $datadir."Latest.pdf";
$cmd = "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$outputName ";
foreach($fileArray as $file) {
    $cmd .= $file." ";
}
$result = shell_exec($cmd);
One odd thing about the above script is I join together colour pdf's, but it outputs a grayscale merged pdf. Is there any reason this could be happening?

Post Reply