Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: Imagemagick / Ghostscript: converting a pdf into a jpg

  1. #1
    Join Date
    Oct 2005
    Location
    Belgium
    Beans
    249
    Distro
    Ubuntu Jaunty Jackalope (testing)

    Imagemagick / Ghostscript: converting a pdf into a jpg

    Hi,
    I'm trying to write a shellscript that converts pdf-s into jpg's, but the jpg's i get as a result are pixelated. Is there a way to make sure I get jpg's with a decent quality? The source pdf's are A3-sized, and the jpg's I get are about 1035x1474, while I need them to be almost double that size to make sure the text is readable.

    this is the command I use:
    Code:
    convert 1.pdf -profile EuroscaleUncoated.icc -profile /usr/share/color/icc/sRGB.icm 1.jpg
    these are the versions I'm using:
    Imagemagick 6.2.4
    Ghostscript 8.15.4
    the OS is Ubuntu Feisty

    Is there a way to improve quality with a switch or something?

  2. #2
    WW is offline Iced Blended Vanilla Crème Ubuntu
    Join Date
    Oct 2004
    Beans
    1,532

    Re: Imagemagick / Ghostscript: converting a pdf into a jpg

    When converting to jpg, you can use the -quality option. The "best" quality would be -quality 100.

  3. #3
    Join Date
    Oct 2005
    Location
    Belgium
    Beans
    249
    Distro
    Ubuntu Jaunty Jackalope (testing)

    Re: Imagemagick / Ghostscript: converting a pdf into a jpg

    -Quality changes the quality of the jpg compression, after rasterizing. The problem is that I want jpegs of a bigger resolution, and ghostscript/imagemagick won't allow me (even with -density and other options i tried)

  4. #4
    Join Date
    Aug 2006
    Location
    Austria
    Beans
    55

    Re: Imagemagick / Ghostscript: converting a pdf into a jpg

    try "-density 200x200"

    edit: ok i didnt read you last post.. density is working fine here, tough.

  5. #5
    Join Date
    Oct 2005
    Location
    Belgium
    Beans
    249
    Distro
    Ubuntu Jaunty Jackalope (testing)

    Re: Imagemagick / Ghostscript: converting a pdf into a jpg

    Thanks for trying anyway This thread has had no comments for weeks, and I still haven't found an adequate solution. Anyway, i've tried again, and it still desn't work. I think there's something wrong with how imagemagick interfaces with Ghostscript.

    If I import the pdf in the gimp (I believe the gimp also uses gs internally for pdf conversion), I can set the resolution to whatever I want, and it works. The colours are all wrong, though, because I can't use a colour profile to convert the colours as they should.

    I want to do it through the command line, because it will be part of a script that converts a bunch of pdf's into jpg's automatically.

    i want to replace an existing program that runs only on Windows, and uses Photoshop for the conversion, because I don't want to:
    1, depend on Photoshop & Windows
    2, have photoshop take all the resources and screen estate while it's running


    edit: I tried with Krita, and Krita gets both the colours right, and the resolution. Is there a way I could use Krita for this, without having it spawn its gui?
    Last edited by Jonne; April 6th, 2007 at 12:38 PM.

  6. #6
    Join Date
    Nov 2004
    Location
    Clemson, SC
    Beans
    271

    Re: Imagemagick / Ghostscript: converting a pdf into a jpg

    Quote Originally Posted by Jonne View Post
    Thanks for trying anyway This thread has had no comments for weeks, and I still haven't found an adequate solution. Anyway, i've tried again, and it still desn't work. I think there's something wrong with how imagemagick interfaces with Ghostscript.
    Have you tried their mailing list?
    http://www.imagemagick.org/mailman/l...o/magick-users

  7. #7
    WW is offline Iced Blended Vanilla Crème Ubuntu
    Join Date
    Oct 2004
    Beans
    1,532

    Re: Imagemagick / Ghostscript: converting a pdf into a jpg

    You can change the size of the output file with the -geometry option, e.g. -geometry 1600x1600 will ensure that the largest dimension is 1600 pixels (it will preserve the aspect ratio). I don't know if this will get you what you want, but it's worth a try. I tried it with a PDF file that contains just some text and equations, and it looked OK, but not great.

    EDIT...
    If I combine -geometry, -density, and -quality, it looks better. For example,
    Code:
    $ convert -geometry 1600x1600 -density 200x200 -quality 100 file.pdf file.jpg
    Then file.jpg looks pretty good to me.
    Last edited by WW; April 6th, 2007 at 01:29 PM.

  8. #8
    Join Date
    Oct 2005
    Location
    Belgium
    Beans
    249
    Distro
    Ubuntu Jaunty Jackalope (testing)

    Re: Imagemagick / Ghostscript: converting a pdf into a jpg

    I think I found it, thanks to WW. Apparently it depends on the syntax you use. If you add the switches before giving the filename of the pdf, it will not ignore -density and such. If you give the filename first (like in the example I posted), Imagemagick will first rasterize the pdf, and only apply the switches afterward, thus giving degraded quality. to recap:
    bad:
    convert file.pdf -density 200x200 file.jpg

    good:
    convert -density 200x200 file.pdf file.jpg

    thanks guys

  9. #9
    Join Date
    Sep 2007
    Beans
    11

    Re: Imagemagick / Ghostscript: converting a pdf into a jpg

    Wow, I just wasted 45 minutes trying to convert a PDF to JPG using every imagemagick option I could find. The default resolution looked horrible. I finally found this post and the problem is solved. Thanks! I'm sure the information is there on the imagemagick website somewhere, but it sure isn't obvious.

  10. #10
    Join Date
    Jan 2007
    Location
    Ridgeland WI US
    Beans
    464
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Imagemagick / Ghostscript: converting a pdf into a jpg

    Thanks WW
    I used your command line.
    Worked fine for me. I converted a one page pdf to a jpg.
    I googled "Ubuntu pdf to jpg" and found this quick solution.

    When I opened this jpg in the GIMP I saw that the GIMP can import pdf and then save as a jpg. Both ways worked. CLI or GUI.
    Last edited by ridgeland; March 14th, 2008 at 11:27 PM. Reason: saw the GIMP can do pdf to jpg
    Gigabyte GA-MA790GPT-UD3H - AMD Phenom II x3 720 - 8 GB RAM - 2009 - My first PC from parts!

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •