Not converting pdf image to png correctly

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
troyd1
Posts: 73
Joined: 2007-07-29T17:13:19-07:00

Not converting pdf image to png correctly

Post by troyd1 »

windows 7 64 bit
Version: ImageMagick 7.0.7-10 Q16 x64 2017-11-05
GS: 9.22 X64

When I do a "convert 00000B26,pdf 00000B26-IM.png" it truncates the image.

I did an export with gimp and it game me a correct image. Any suggestions?

I just installed the latest version of IM and GS.

The files are here:
https://drive.google.com/drive/folders/ ... 2Nmek9sNGM
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Not converting pdf image to png correctly

Post by fmw42 »

With IM 7 you should use magick, not convert. Your command works fine for me on IM 7.0.7.10 Q16 Mac OSX with GS 9.21, but your image has an alpha channel. Using identify the alpha channel shows min (white) and max (black), which is backwards. Using magick identify, I get the proper values. What is happening is that your alpha channel is blanking out the rest of the image. So you need to turn it off or flatten it against white. Using a larger density will give a bigger image, but higher quality. You can also resize reading the PDF (by 25%) to get back to default size. (default density is 72. so 72*4=288 thus 25 % reduction).

But a better conversion could be had with

Code: Select all

magick -density 288  00000B26.pdf -background white -flatten 00000B26.png
troyd1
Posts: 73
Joined: 2007-07-29T17:13:19-07:00

Re: Not converting pdf image to png correctly

Post by troyd1 »

I am doing more things, but just pared down my command to show a simple example of it not working. I tried the magick command and am getting the same result as the convert. Just the header and nothing more. I added the -background white and -flatten and it gave me a full page, it still gave me the header, but the rest is still missing. Can you provide the code that you used that worked? I tried the command that you suggested: magick -density 288 00000B26.pdf -background white -flatten 00000B26.png and it did the same thing. I put the image created on the link and called it 00000B26x.png.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Not converting pdf image to png correctly

Post by fmw42 »

This works for me on IM 7.0.7.10 Q16 Mac OSX and GS 9.21

Code: Select all

magick -density 325  00000B26.pdf -resize 25% -background white -flatten 00000B26.png
Image
troyd1
Posts: 73
Joined: 2007-07-29T17:13:19-07:00

Re: Not converting pdf image to png correctly

Post by troyd1 »

Do you think it could be just the 1 version difference in ghostscript?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Not converting pdf image to png correctly

Post by fmw42 »

I suppose it is possible. Also check your delegates.xml file.

Unix:

Code: Select all

find /usr | grep "delegates.xml"
/usr/local/etc/ImageMagick-6/delegates.xml

Does your line:

<delegate decode="ps:alpha" stealth="True" command="&quot;gs&quot; -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pngalpha&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;-f%s&quot; &quot;-f%s&quot;"/>


show sDEVICE=pngalpha or pnmraw?

If not pngalpha, then change it to pngalpha
troyd1
Posts: 73
Joined: 2007-07-29T17:13:19-07:00

Re: Not converting pdf image to png correctly

Post by troyd1 »

I am on windows. Where would it be?

Also, I believe it worked for you, just trying to figure out why it is not working for me.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Not converting pdf image to png correctly

Post by fmw42 »

Sorry, I do not use Windows and don't know the file structure there. Perhaps one of the Windows users will see this shortly and can answer that better. Do you know whether ImageMagick can find Ghostscript? Probably not the issue since you did not get an error message about that.

But just to be sure, if you do

Code: Select all

convert -list configure
Does the line starting with DELEGATES show gs or gslib?

DELEGATES bzlib mpeg fftw fontconfig freetype gslib jbig jng jpeg lcms lqr lzma openexr openjp2 png ps rsvg tiff webp x xml zlib

Not sure if it shows on Windows systems or not.

Can you backdown your Ghostscript version and see if that works?

Or try converting your PDF using Ghostscript standalone?

Do you have OpenMP or OpenCL configured? You could try recompiling without them. Or set the threads to 1 to see if that helps. See viewtopic.php?f=2&t=20756&p=83407&hilit=thread#p83407
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Not converting pdf image to png correctly

Post by snibgo »

On Windows, delegates.xml is usually in the same directory as convert.exe.

When I try to open the PDF with Adobe Reader, I get a message: "A font package is required to correctly display this page." If I don't download these fonts, Adobe Reader shows only the header, and IM convert creates just the header. "Document properties" says the font is "MSung-Light".
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: Not converting pdf image to png correctly

Post by fmw42 »

Did you install all the Ghostscript fonts? See the links to them at http://www.imagemagick.org/download/delegates/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Not converting pdf image to png correctly

Post by snibgo »

Who, me? No, I haven't installed more fonts for Ghostscript than comes in the standard package. And this might be the OP's problem, that the PDF uses a non-standard font that isn't embedded in the PDF. Installing extra fonts may cure the problem.

In any case, if Adobe Reader can't rasterise a PDF, there is little chance of Ghostscript doing any better.
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: Not converting pdf image to png correctly

Post by fmw42 »

fmw42 wrote: 2017-11-10T15:30:39-07:00 Did you install all the Ghostscript fonts? See the links to them at http://www.imagemagick.org/download/delegates/
I meant this for the OP.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Not converting pdf image to png correctly

Post by snibgo »

When reading a PDF makes "a low definition and low size" output, this is usually because the density setting is too low. Try "-density 300" or some other number before the pdf, eg:

Code: Select all

magick -density 300 in.pdf out.png
snibgo's IM pages: im.snibgo.com
troyd1
Posts: 73
Joined: 2007-07-29T17:13:19-07:00

Re: Not converting pdf image to png correctly

Post by troyd1 »

Sorry I did not reply sooner, was out. Here is my:
c:\>convert -list configure

Path: [built-in]

Name Value
-------------------------------------------------------------------------------
FEATURES OpenMP
NAME ImageMagick
QuantumDepth 16

Path: C:\Program Files\ImageMagick-7.0.7-Q16\configure.xml

Name Value
-------------------------------------------------------------------------------
CC vs10
COPYRIGHT Copyright (C) 1999-2017 ImageMagick Studio LLC
DELEGATES bzlib freetype jpeg jp2 lcms png raw tiff x11 xml wmf zlib
FEATURES OpenMP
HOST Windows
LIB_VERSION 0x707
LIB_VERSION_NUMBER 7,0,7,10
NAME ImageMagick
RELEASE_DATE 2017-12-21
VERSION 7.0.7
WEBSITE http://www.imagemagick.org

I do not see and GS. How do I add that in windows?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Not converting pdf image to png correctly

Post by snibgo »

troyd1 wrote:I do not see and GS. How do I add that in windows?
Why do you want to? IM is successfully running GS.

I suspect the problem is a missing font. Can Adobe Reader read your PDF?
snibgo's IM pages: im.snibgo.com
Post Reply