Convert large pdf file to image

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
kasthuri
Posts: 5
Joined: 2014-02-12T21:03:28-07:00
Authentication code: 6789

Convert large pdf file to image

Post by kasthuri »

I tried to convert the pdf file sized 10MB to jpg format using Imagemagick convert function with -geometry 300, but it turn up to be black image. Can anyone help me with this issue?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert large pdf file to image

Post by fmw42 »

what was your exact command. what version of IM and what platform. do you have ghostscript delegate installed

what do you get from

convert -version
kasthuri
Posts: 5
Joined: 2014-02-12T21:03:28-07:00
Authentication code: 6789

Re: Convert large pdf file to image

Post by kasthuri »

Thank you for your response. Imagemagick version that I'm using is ImageMagick-6.8.6-Q16 with windows 8 platform and PHP. I have installed ghostscript g910w32.
The convert command i have used is

$im = new phmagick();
$im->execute("convert -quality 100 -density 300 -geometry 200 drawing_primer.pdf[0] $output");
echo '<pre>';
print_r($im->getLog());
echo '</pre>';

Array
(
[0] => Array
(
[cmd] => convert -quality 100 -density 300 -geometry 200 drawing_primer.pdf[0] convert/drawing_primer.jpg
[return] => 0
[output] => Array
)
)

this was the output but my image looks blank and black.

*** note my pdf file size is 343kb and consist of only one page.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert large pdf file to image

Post by fmw42 »

what do you get back from

convert -version

or

convert -list configure

at the line starting wth Delegates.

Does it include gs (ghostscript)?

If it does, please upload your pdf file to some free hosting service such as dropbox (public folder) and put a link here so others can check your image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert large pdf file to image

Post by snibgo »

Is the document black text on a transparent (ie black-transparent) background? If so then putting "-background white" before or after the PDF may cure the problem.
snibgo's IM pages: im.snibgo.com
kasthuri
Posts: 5
Joined: 2014-02-12T21:03:28-07:00
Authentication code: 6789

Re: Convert large pdf file to image

Post by kasthuri »

Hi,

I have tried -background white but the result was still same.

https://www.dropbox.com/s/4w7m6rudqpcsg ... primer.pdf - this is the original file to be converted
https://www.dropbox.com/s/0wwik94hx2w2um4/drawing1.jpg - this is the output file.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert large pdf file to image

Post by fmw42 »

This works just fine for me on IM 6.8.0.5

Code: Select all

convert -density 300 -background white drawing_primer.pdf[0] drawing_primer.jpg
You need to set a white backgorund since jpg does not support transparency

$im = new phmagick();
what is phmagick? do you mean Imagick? or are you just trying to use PHP exec() command. If the latter, I do not think your syntax is correct, but I am not a PHP expert.

Try either

Code: Select all

<?php
exec("convert -density 300 -background white drawing_primer.pdf[0] drawing_primer.jpg",$out,$returnval);
{echo "$out<br>";}
echo "<br>";
?>
or

Code: Select all

<?php
exec("fullpath2/convert -density 300 -background white drawing_primer.pdf[0] drawing_primer.jpg",$out,$returnval);
{echo "$out<br>";}
echo "<br>";
?>


The only other issue I can think of is that your ps delegate needs to be using sDEVICE=pngalpha since you have a pdf with transparency.

check your delegates.xml file


<delegate decode="ps:alpha" stealth="True" command=""gsc" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s""/>
kasthuri
Posts: 5
Joined: 2014-02-12T21:03:28-07:00
Authentication code: 6789

Re: Convert large pdf file to image

Post by kasthuri »

thank you very much now it works fine for me. but i just want to ask why if insert -resize or -geometry the output back to as previous.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert large pdf file to image

Post by fmw42 »

-geometry is not the right command. If you want to add -resize, then do that after reading the pdf file.

Code: Select all

convert -density 288-background white drawing_primer.pdf[0] -resize 25% drawing_primer.jpg
That will expand the pdf and then resize it back to the original 72 dpi. But you may need a higher output resolution. That is why I just used -density 300 (or -density 288). The output size is controlled by the -density argument. The only reason to resize down again is if you want to match 72 dpi for example, but then the image will be smaller and may not give you adequate resolution for your lines.
kasthuri
Posts: 5
Joined: 2014-02-12T21:03:28-07:00
Authentication code: 6789

Re: Convert large pdf file to image

Post by kasthuri »

Thank you very much.. now I understand better... really appreciate your help...

Thank you...
Post Reply