converting pdf only works sometimes

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
haskinsj87

converting pdf only works sometimes

Post by haskinsj87 »

i have two, one page pdf files im testing this on. heres the code im using (in a php script)

exec('convert -density 300x300 plan.pdf -crop 2880x2880 plan.jpg');

if i take out "-density 300x300" it defaults to 72, which makes the jpg a lot smaller than the original pdf(it needs to stay the same size). also if that is removed, everything works fine, i just have a smaller image. however, the way it currently is, it will only work on the smaller pdf (135KB, 7000x5000 px). on the larger pdf (1.28MB, 10800x14400 px) it doest ever finish. i sometimes get a few pieces of the picture but thats about all. if i take out "-crop 2880x2880" i get nothing at all on the larger pdf. any ideas as to why the conversion isnt working?

thanks
haskinsj87

Re: converting pdf only works sometimes

Post by haskinsj87 »

I guess i wasnt giving this enough time. it took about 30 min. but the following finally worked as expected:

exec('convert -density 300x300 plan.pdf -crop 2880x2880 plan.jpg');

however, if i remove "-crop 2880x2880" still dont get any results. a file "plan.jpg" is generated on the server, but has a size of 0KB and no content.
any ideas of what to do to speed this up?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: converting pdf only works sometimes

Post by magick »

To speed up the conversion, use Ghostscript instead of ImageMagick to convert PDF to JPEG.
haskinsj87

Re: converting pdf only works sometimes

Post by haskinsj87 »

thank you for the quick reply. i dont really know a whole lot here. i tried the following

exec('gs -q -dNOPAUSE -sDEVICE=jpeg -dJPEGQ=100 -r300-sOutputFile=plan2.jpg plan2.pdf');

but i did not get any results. do you have any more advice, or could you point me somewhere where i could find some more info?

thanks again
haskinsj87

Re: converting pdf only works sometimes

Post by haskinsj87 »

i also tried to take the pdf, convert it in photoshop, so now i have a jpg 10400x14400 px, and just work with that.

exec('convert -crop 2880x2880 plan.jpg');

i thought maybe i can work around converting from pdf and just go straight to cropping. however, this approach also took a long time to complete. any thoughts?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: converting pdf only works sometimes

Post by magick »

See http://www.imagemagick.org/script/architecture.php. When your image gets larger so does the memory requirements. Eventually ImageMagick cannot allocate enough memory so it caches the image pixels to disk which is quite slow as you experienced. Your only options are to accept it is slow, add more memory to your computer, or use some other program other than ImageMagick.
Post Reply