convert a series of png's to one pdf -to many?

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
silversun
Posts: 7
Joined: 2013-09-13T06:59:00-07:00
Authentication code: 6789

convert a series of png's to one pdf -to many?

Post by silversun »

I am annotating a series of png's - 10 images right now - with text and then I am converting them to a single pdf.

the annotation which works fine produces a png with an average size of 200k:

Code: Select all

convert 001.png -pointsize 42 -gravity NorthWest -annotate +2176.92307692+272.769230769 '13' -annotate +1469.23076923+1053.53846154 'round rock' -annotate +319.230769231+953.538461538 '1400 wroxton way' -annotate +2065.38461538+1049.69230769 '78664' -annotate +1980.76923077+2199.69230769 '75000.00' img_tmp/001.png
Then I take all the new images and convert them to a pdf. The problem is that if I have more than 5 images or over 1.3meg it seems the resulting pdf has a header of PNG (not really a pdf document) and only the first page. It is not actually a pdf file. 5 or less images and the resulting pdf is viewable with all pages.

my code for pdf conversion.

Code: Select all

convert -density 150 img_tmp/001.png img_tmp/002.png img_tmp/003.png img_tmp/004.png img_tmp/005.png img_tmp/006.png img_tmp/007.png img_tmp/008.png img_tmp/009.png img_tmp/010.png img_tmp/offer.pdf
I have made sure that the php memory limit and time limit are sufficient. Does anyone know why Imagick can not convert more than 6 images to one pdf?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert a series of png's to one pdf -to many?

Post by snibgo »

ImageMagick can convert any number of PNG files into a single PDF.

I know nothing about PHP and IMagick. You may be hitting a limit on command length.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert a series of png's to one pdf -to many?

Post by fmw42 »

Process it outside of PHP in a terminal window and see if that fails. If not, then it is PHP limitations. If it fails, then you may be running out of memory or perhaps your tmp directory is limited.

I do not know if this is relevant, but see http://www.imagemagick.org/Usage/files/#massive

Also see
http://www.imagemagick.org/script/resou ... nvironment


Note also that properly the -density in this command should be after reading all the input images and before your pdf output. But it may still work as you have it.
silversun
Posts: 7
Joined: 2013-09-13T06:59:00-07:00
Authentication code: 6789

Re: convert a series of png's to one pdf -to many?

Post by silversun »

Thanks Guys!!

I found the error.

one of the images is a small picture of a check. So it is not a full page with white space like the rest of the png's which are copies of an original pdf doc.

If i remove this image from the list everything works. try to convert the check image to pdf on its own and it fails.

Any ideas on this?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert a series of png's to one pdf -to many?

Post by snibgo »

What error messages do you get?

Try the following:
convert cheque.png x.jpg
identify -verbose cheque.png
identify cheque.png
snibgo's IM pages: im.snibgo.com
silversun
Posts: 7
Joined: 2013-09-13T06:59:00-07:00
Authentication code: 6789

Re: convert a series of png's to one pdf -to many?

Post by silversun »

if i try that on the (007.png)check.png it returns empty. The $out array is empty and the $ret1 is set (error). The new007.jpg is not created.

i tested on a standard page and it returns a lot of info.

Code: Select all

        exec('convert 5231c415edcc9/007.png new007.jpg');
        exec('identify -verbose 5231c415edcc9/007.png', $out, $ret);
        exec('identify 5231c415edcc9/007.png',$out2, $ret2);
;

These PNG's are coming from a PDF file. Each page is converted to PNG with ghostscript. So if one of the pages is nothing more than an image of a check should i be doing something in that process?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert a series of png's to one pdf -to many?

Post by snibgo »

What happens when you run those commands from the command line?
snibgo's IM pages: im.snibgo.com
silversun
Posts: 7
Joined: 2013-09-13T06:59:00-07:00
Authentication code: 6789

Re: convert a series of png's to one pdf -to many?

Post by silversun »

i do not have shell access :(
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert a series of png's to one pdf -to many?

Post by snibgo »

Can you copy the problem file to somewhere like Dropbox and post the URL here?

Otherwise, I can only suggest that you try to "identify" each file before using it. If that fails, throw an error.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert a series of png's to one pdf -to many?

Post by fmw42 »

Post a link to the bad image so we can examine it. You can upload to any free image hosting server and then put a like to it here.
Post Reply