PDF to JPG can not be viewed in IE6 or IE7

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
brettalton

PDF to JPG can not be viewed in IE6 or IE7

Post by brettalton »

So, for work, I was asked to convert PDF files into JPG images.

Immediately I thought of ImageMagick and wrote this:

Code: Select all

for file in `ls *.pdf`; do
	convert $file -resize 800x800 `echo $file | sed 's/\.pdf$/\.jpg/'`
done
Unfortunately, for some reason, the .jpg file can not show up in IE7 on Windows XP and Vista, nor IE6 through Wine on Linux. It works in Firefox, GIMP, Image Viewer (Gnome), some KDE applications, etc.

Is there a header I'm missing?

I also ran the command 'file' to see if the file was recognized as a JPG. It was of course, including the .jpg that was converted from a PDF file before I was hired (in folder 'old').
$ file page01.jpg
page01.jpg: JPEG image data, JFIF standard 1.01

$ file old/page01.jpg
old/page01.jpg: JPEG image data, JFIF standard 1.01
Last edited by brettalton on 2008-10-10T12:47:43-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PDF to JPG can not be viewed in IE6 or IE7

Post by fmw42 »

I am on a Mac and in Safari, all I see is black. It shows fine in Firefox and Opera.

I would question one of several things.

What is the format of the image in the PDF and is it a "good" image? Can you extract that image from your PDF and display it in any/every browser?

Is the image in your PDF in RGB or CMYK format?

Try doing the convert on a single image with a simple command line? Perhaps add -colorspace RGB.

I am not too sure of this, but try

convert -colorspace RGB image.pdf -resize 800x800 output.jpg

Try also some other format like PNG or GIF and see if that displays in any/every browser.

Someone like Anthony, may be able to give you more information about properly converting from PDF to JPG and any issues there. But see

http://www.imagemagick.org/Usage/formats/
(particularly about JPG and potentially about changing colorspaces and profiles, if that is relevant, and also other formats section regarding PDF). Note I believe IM uses Ghostscript to convert from PDF, so your Ghostscript may be an/the issue.

Hopefully, someone more knowledgeable, such as Anthony or Magick, can help you more directly.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PDF to JPG can not be viewed in IE6 or IE7

Post by magick »

Add -interlace none to your command line to turn off progressive encoding.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PDF to JPG can not be viewed in IE6 or IE7

Post by fmw42 »

I am no expert on these matters, but I looked at the verbose info:

identify -verbose page01.jpg
Image: page01.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Class: DirectClass
Geometry: 618x800+0+0
Resolution: 72x72
Print size: 8.58333x11.1111
Units: PixelsPerInch
Type: ColorSeparation
Endianess: Undefined
Colorspace: CMYK
...
Interlace: None


And it appears to be CMYK with no interlace. So I suspect not all browsers can display CMYK jpg images. You can try converting to RGB.

I am not too sure how you do that, but you can try (according to the search results below):

convert -colorspace RGB image.pdf -resize 800x800 output.jpg



The page at http://www.imagemagick.org/Usage/formats/ may help.

You can also search these archives for "CMYK PDF" topics and see if this has been answered before, which appears to be the case.

See for example these two:
viewtopic.php?f=3&t=11514&p=37094&hilit=CMYK+PDF#p37094
viewtopic.php?f=1&t=10933&hilit=cmyk+pdf
brettalton

Re: PDF to JPG can not be viewed in IE6 or IE7

Post by brettalton »

Thanks everyone, it was because it was in CMYK mode, you were all right!

Code: Select all

-colorspace RGB
Does the trick! Thanks!
sushil.prajapati
Posts: 1
Joined: 2011-08-16T00:16:00-07:00
Authentication code: 8675308

Re: PDF to JPG can not be viewed in IE6 or IE7

Post by sushil.prajapati »

Thanks everyone it works for me... :)

-colorspace RGB
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: PDF to JPG can not be viewed in IE6 or IE7

Post by anthony »

brettalton wrote:Immediately I thought of ImageMagick and wrote this:

Code: Select all

for file in `ls *.pdf`; do
	convert $file -resize 800x800 `echo $file | sed 's/\.pdf$/\.jpg/'`
done
Not really part of the actual problem but what about using...

Code: Select all

   convert "$file" -resize 800x800 -set filename:f '%t'  '%[filename:f].jpg' 
Note that %t does not include the directory path component %d

instead of the sub-shell expression. It then does not matter if the input is PDF, postscript, or something else!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply