help reading PDF

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?".
jimbobjones

help reading PDF

Post by jimbobjones »

Hi, I'm using a Fedora Core 6 server with the following setup:-
ImageMagick 6.2.8 04/05/07 Q16
Ghostscript version: 8.15.4

When I try to convert the attached PDF, I get a skewed image no matter what the output format. I've tried JPG, GIF, PNG, EPS all with exactly the same skewed results! Can anyone help me with a solution to this as its a real problem for our clients.

I've linked three files :- The good.jpg file was created on a seperate server with the same version of imagemagick but a slightly older version of ghostscript.

My command to convert was:-
convert "in.pdf"[0] good.jpg

Hope you can help me!
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: help reading PDF

Post by el_supremo »

FYI: works for me with:
ImageMagick 6.4.4 2008-10-09 Q8 http://www.imagemagick.org
GPL Ghostscript 8.63 (2008-08-01)

Might be worth your while updating IM and GS if you can.

Pete
jimbobjones

Re: help reading PDF

Post by jimbobjones »

I'd really like to - but I'm worried about borking the current install of IM and not being able to get it back without a server re-image. I tried to download the latest version of imagemagick on a local test server and did a make from the sources; however I couldn't get it to product JPG or PNG's - GIF's work however strangley! I think this may be to do with dependencies and/or configuration but there's so many options to configure I'm a bit lost at sea I'm afraid.

Is there any further debug I can post to help move towards upgrading?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: help reading PDF

Post by fmw42 »

jimbobjones wrote:I'd really like to - but I'm worried about borking the current install of IM and not being able to get it back without a server re-image. I tried to download the latest version of imagemagick on a local test server and did a make from the sources; however I couldn't get it to product JPG or PNG's - GIF's work however strangley! I think this may be to do with dependencies and/or configuration but there's so many options to configure I'm a bit lost at sea I'm afraid.

Is there any further debug I can post to help move towards upgrading?
You likely need to install the delegate libraries for all the image types you want to work with.

convert -list configure

Look for DELEGATES. Mine says

DELEGATES bzlib fontconfig freetype gs jpeg jp2 lcms lqr openexr png tiff x11 xml zlib

If you are missing delegates, then you can get them at: http://www.imagemagick.org/download/delegates/

Install the delegates you want then reinstall IM
jimbobjones

Re: help reading PDF

Post by jimbobjones »

I can't see any DELEGATES line - but I can tell you that it produces JPG's from other PDF's no problem. The output of "convert -list configure" is :-

Code: Select all

Path: /usr/lib64/ImageMagick-6.2.8/config/configure.xml

Name          Value
-------------------------------------------------------------------------------
CC            gcc
CFLAGS        -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wall -pthread
CONFIGURE     ./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --target=x86_64-redhat-linux-gnu --program-prefix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/usr/com --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --with-modules --with-perl --with-x --with-threads --with-magick_plus_plus --with-gslib --with-wmf --with-lcms --with-rsvg --with-xml --with-perl-options=INSTALLDIRS=vendor CC='gcc -L/builddir/build/BUILD/ImageMagick-6.2.8/magick/.libs' LDDLFLAGS='-shared -L/builddir/build/BUILD/ImageMagick-6.2.8/magick/.libs' --with-windows-font-dir=/usr/share/fonts/default/TrueType --without-dps
COPYRIGHT     Copyright (C) 1999-2005 ImageMagick Studio LLC
CPPFLAGS      -I/usr/include
CXX           g++
CXXFLAGS      -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -pthread
DEFS          -DHAVE_CONFIG_H
DISTCHECK_CONFIG_FLAGS 'CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'  --with-quantum-depth=16  --with-dps=no  --with-fpx=no  --with-fontpath=  --with-windows-font-dir==/usr/share/fonts/default/TrueType 
EXEC-PREFIX   /usr
HOST          x86_64-redhat-linux-gnu
LDFLAGS       -L/usr/lib64 -L/usr/lib64 -lfreetype -L/usr/lib
LIB_VERSION   0x628
LIB_VERSION_NUMBER 6,2,8,0
LIBS          -lMagick -llcms -ltiff -lfreetype -ljpeg -lfontconfig -lXext -lSM -lICE -lX11 -lXt -lbz2 -lz -lpthread -lm -lpthread
NAME          ImageMagick
PCFLAGS       
PREFIX        /usr
QuantumDepth  16
RELEASE_DATE  04/05/07
VERSION       6.2.8
WEBSITE       http://www.imagemagick.org
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: help reading PDF

Post by fmw42 »

jimbobjones wrote:I can't see any DELEGATES line - but I can tell you that it produces JPG's from other PDF's no problem. The output of "convert -list configure" is :-

Code: Select all

Path: /usr/lib64/ImageMagick-6.2.8/config/configure.xml

Name          Value
-------------------------------------------------------------------------------
CC            gcc
CFLAGS        -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wall -pthread
CONFIGURE     ./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --target=x86_64-redhat-linux-gnu --program-prefix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/usr/com --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --with-modules --with-perl --with-x --with-threads --with-magick_plus_plus --with-gslib --with-wmf --with-lcms --with-rsvg --with-xml --with-perl-options=INSTALLDIRS=vendor CC='gcc -L/builddir/build/BUILD/ImageMagick-6.2.8/magick/.libs' LDDLFLAGS='-shared -L/builddir/build/BUILD/ImageMagick-6.2.8/magick/.libs' --with-windows-font-dir=/usr/share/fonts/default/TrueType --without-dps
COPYRIGHT     Copyright (C) 1999-2005 ImageMagick Studio LLC
CPPFLAGS      -I/usr/include
CXX           g++
CXXFLAGS      -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -pthread
DEFS          -DHAVE_CONFIG_H
DISTCHECK_CONFIG_FLAGS 'CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'  --with-quantum-depth=16  --with-dps=no  --with-fpx=no  --with-fontpath=  --with-windows-font-dir==/usr/share/fonts/default/TrueType 
EXEC-PREFIX   /usr
HOST          x86_64-redhat-linux-gnu
LDFLAGS       -L/usr/lib64 -L/usr/lib64 -lfreetype -L/usr/lib
LIB_VERSION   0x628
LIB_VERSION_NUMBER 6,2,8,0
LIBS          -lMagick -llcms -ltiff -lfreetype -ljpeg -lfontconfig -lXext -lSM -lICE -lX11 -lXt -lbz2 -lz -lpthread -lm -lpthread
NAME          ImageMagick
PCFLAGS       
PREFIX        /usr
QuantumDepth  16
RELEASE_DATE  04/05/07
VERSION       6.2.8
WEBSITE       http://www.imagemagick.org

Apparently your IM version is way too old and did not have DELEGATES listed in the convert -list configure at that time. I think the LIBS line was the old equivalent to the DELEGATES line. So you have tiff and jpeg for example, but no ghostscript (gs) for handling pdfs. I do not know how to help any further. Sorry. Try installing ghostscript
jimbobjones

Re: help reading PDF

Post by jimbobjones »

Hi there - thanks for your help, but it does convert *most* PDF's - just a few it stumbles on. Is there anyway I can debug imagemagick and see where its falling down?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: help reading PDF

Post by anthony »

The actual process is that IM uses ghostscript to generate either PNG or PPM raster images from the PDF. Which one depends on the postscript level and whether transparency is involved.

I believe -verbose, will let you see the ghostscript call IM uses for that step.

Calling IM with

Code: Select all

convert  image.pdf  image.ppm
or whatever format the ghostscrpt delegate command is producing should let you see exactly what ghostscript produced for IM to read without IM actually reading that image (just coping it to the destination image).

From there you can check to see if ghostscript is producing the right image, or not, and you can figure out what is going on.

NOTE: the IM that your machine has installed is most likely and RPM package, it is very posible to clear out IM completely and re-install the original packages without problems. That is the beauty of RPM packages that fedora uses.

In a couple of other forum discussions I have given the methods I use for ensuring the system is clear of RPM's as well as how I compile IM into a source-RPM and from that into a installable RPM for use under a fedora system.

PS: my firefox reports your 'good' JPG image has errors making the image undisplayable.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
jimbobjones

Re: help reading PDF

Post by jimbobjones »

Hi there, thanks for your advice. I tried the verbose option as follows:-

convert "No. 9 HDS2 Cap wiper options 02 UK.pdf"[0] -verbose test.jpg

The output it gave me was:

No. 9 HDS2 Cap wiper options 02 UK.pdf[0]=>test.jpg PDF 595x842 595x842+0+0 DirectClass 1.2e+02kb

Thats it! So I'm not sure if I can see the GS call in there.

I did just make another breakthrough however. I used Acrobat to republish the PDF at postscript level 2 and now the document converts to JPG fine! Is there any reason why Imagemagick or Ghostscript would have a problem with ps level 3? Also - are there any ways I can verify this is a ghostscript problem and upgrade to a compatible version of GS if that is indeed the case?

Look forward to your comments! Cheers
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: help reading PDF

Post by anthony »

Try adding -verbose BEFORE reading so it is set during the read operation.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
jimbobjones

Re: help reading PDF

Post by jimbobjones »

Hi, thanks for the tip! Loads more debugging now:-

Here's the output with the postscript lvl 3 file:-

Code: Select all

[root@server8 ~]# convert -verbose "No. 9 HDS2 Cap wiper options 01 UK.pdf"[0] test.jpg
[ghostscript library] -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 -dEPSCrop "-sDEVICE=bmpsep8" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-g595x842" "-r72x72" -dFirstPage=1 -dLastPage=1 "-sOutputFile=/tmp/magick-XXb9wu3A" "-f/tmp/magick-XXeK0i2p" "-f/tmp/magick-XX7j6b1e"/tmp/magick-XXb9wu3A BMP 595x842 595x842+0+0 PseudoClass 256c 1.9mb
No. 9 HDS2 Cap wiper options 01 UK.pdf[0]=>No. 9 HDS2 Cap wiper options 01 UK.pdf PDF 595x842 595x842+0+0 PseudoClass 256c 1.9mb
No. 9 HDS2 Cap wiper options 01 UK.pdf[0]=>test.jpg PDF 595x842 595x842+0+0 PseudoClass 256c 46kb
And with the postscript lvl 2 file :-

Code: Select all

[root@server8 ~]# convert -verbose "No. 9 HDS2 Cap wiper options 02 UK.pdf"[0] test.jpg
[ghostscript library] -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 -dEPSCrop "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-g595x842" "-r72x72" -dFirstPage=1 -dLastPage=1 "-sOutputFile=/tmp/magick-XXq0cHmc" "-f/tmp/magick-XXUhLxsM" "-f/tmp/magick-XXpPDsym"/tmp/magick-XXq0cHmc PNM 595x842 595x842+0+0 DirectClass 1.4mb
No. 9 HDS2 Cap wiper options 02 UK.pdf[0]=>No. 9 HDS2 Cap wiper options 02 UK.pdf PDF 595x842 595x842+0+0 DirectClass 1.4mb
No. 9 HDS2 Cap wiper options 02 UK.pdf[0]=>test.jpg PDF 595x842 595x842+0+0 DirectClass 1.2e+02kb
Does that give any hints as to why the lvl 3 convert fails?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: help reading PDF

Post by anthony »

The only difference in the delegate specifications is the output image format requested from ghostscript.

Try adding a -channel RGBA before the PDF file read, which hopefully will switch the delegate to the png output method.

For more info see IM Examples
Postscript/PDF text formating
http://www.imagemagick.org/Usage/text/#postscript
Postscript/PDF common file format notes
http://www.imagemagick.org/Usage/formats/#ps

Also a previous forum topic has the suggestion that you edit the system installed "delegate.xml" file and replace "-sDEVICE=bmpsep8" with "-sDEVICE=bmp16".

I have no guarantees about this, but please let me know if you try this and it works.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
jimbobjones

Re: help reading PDF

Post by jimbobjones »

Hi, thanks for the reply, I tried your suggestions:

Adding -channel RGBA before the PDF read gives:-

Code: Select all

convert -channel RGBA -verbose "No. 9 HDS2 Cap wiper options 01 UK.pdf"[0] test.jpg
[ghostscript library] -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 -dEPSCrop "-sDEVICE=bmpsep8" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-g595x842" "-r72x72" -dFirstPage=1 -dLastPage=1 "-sOutputFile=/tmp/magick-XX75RCPO" "-f/tmp/magick-XXhA8G5O" "-f/tmp/magick-XXmesfmP"/tmp/magick-XX75RCPO BMP 595x842 595x842+0+0 PseudoClass 256c 1.9mb
No. 9 HDS2 Cap wiper options 01 UK.pdf[0]=>No. 9 HDS2 Cap wiper options 01 UK.pdf PDF 595x842 595x842+0+0 PseudoClass 256c 1.9mb
No. 9 HDS2 Cap wiper options 01 UK.pdf[0]=>test.jpg PDF 595x842 595x842+0+0 PseudoClass 256c 46kb
And the result jpg file is still scrambled.

As for the delegate.xml changes - I have searched my system using find / -name delegate.xml and there doesn't seem to be one!

I should tell you - this server is a 64 bit Centos 5.2

The local box which can do the convert without any trouble is 32 bit.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: help reading PDF

Post by fmw42 »

jimbobjones wrote:Hi, thanks for the reply, I tried your suggestions:

Adding -channel RGBA before the PDF read gives:-

Code: Select all

convert -channel RGBA -verbose "No. 9 HDS2 Cap wiper options 01 UK.pdf"[0] test.jpg
[ghostscript library] -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 -dEPSCrop "-sDEVICE=bmpsep8" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-g595x842" "-r72x72" -dFirstPage=1 -dLastPage=1 "-sOutputFile=/tmp/magick-XX75RCPO" "-f/tmp/magick-XXhA8G5O" "-f/tmp/magick-XXmesfmP"/tmp/magick-XX75RCPO BMP 595x842 595x842+0+0 PseudoClass 256c 1.9mb
No. 9 HDS2 Cap wiper options 01 UK.pdf[0]=>No. 9 HDS2 Cap wiper options 01 UK.pdf PDF 595x842 595x842+0+0 PseudoClass 256c 1.9mb
No. 9 HDS2 Cap wiper options 01 UK.pdf[0]=>test.jpg PDF 595x842 595x842+0+0 PseudoClass 256c 46kb
And the result jpg file is still scrambled.

As for the delegate.xml changes - I have searched my system using find / -name delegate.xml and there doesn't seem to be one!

I should tell you - this server is a 64 bit Centos 5.2

The local box which can do the convert without any trouble is 32 bit.
Try delegates.xml

It is plural!
jimbobjones

Re: help reading PDF

Post by jimbobjones »

Hi - yes I found the delegates.xml file and made the changes you suggested as follows,
Line 80 becomes:-

Code: Select all

<delegate decode="ps:cmyk" stealth="True" command='"gs" -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 -dEPSCrop "-sDEVICE=bmp16" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-g%s" "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"' />
Line 99 becomes:-

Code: Select all

<delegate decode="pcl-cmyk" stealth="True" command='"pcl6" -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 -dEPSCrop "-sDEVICE=bmp16" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-g%s" "-r%s" %s "-sOutputFile=%s" "%s"' />
This does work however - the result image looks like its got the wrong colour profile. All the saturation of the colours is way out; I think the source must have been CYMK and its displaying as though its an RGB profile.

Any ideas how I can fix that?

Thanks for all your kind help :)
Post Reply