Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^3: Convert PDF to HTML (or JPEG)

by almut (Canon)
on Sep 12, 2009 at 17:33 UTC ( #794933=note: print w/replies, xml ) Need Help??

in reply to Re^2: Convert PDF to HTML (or JPEG)
in thread Convert PDF to HTML (or JPEG)

Yes, convert has an -antialias switch, but not GhostScript — at least not the jpeg driver (there's an x11alpha screen driver, but I think that's the only one which does anti-aliasing by itself).  And ImageMagick (i.e. convert) cannot render PDF/PS itself; it uses GhostScript for that under the hood, anyway...

Personally, I prefer to use both tools separately, because then I have fine control over the parameters used during conversion, and so far, I've always achieved better results (in less time) than when trying to convince convert alone to do what I want.

For example, the naive approach (which I figure should be comparable to the conversions I posted above) when using convert directly would be something like this:

$ convert input.pdf -density 150 -geometry 1240x1754 -antialias -quali +ty 90 img%d.jpg

But the results are much worse than when doing the steps separately... (example: test1.jpg, test2.jpg — where test1.jpg has been produced by using gs and convert separately, and test2.jpg when calling gs indirectly via convert (the command right above)).

As I read the docs, -density is supposed to set the resolution ("set resolution of an image for rendering to devices"), however, for some reason this doesn't seem to be passed on to Ghostscript (as can be revealed using strace)...  In case you have the patience to figure out the correct incantation of options for convert that achieves the quality of test1.jpg, please let me know (input PDF here) — IMHO, there's too much Magick going on :)

Replies are listed 'Best First'.
Re^4: Convert PDF to HTML (or JPEG)
by LanX (Bishop) on Sep 14, 2009 at 20:56 UTC
    Hi Almut,

    Now I had the time to check my old computer for these 8 year old bash scripts I used :)

    And ... well ... it's really strange, but I'm not experiencing your problems!



    that's the script I used:

    cd /home/lanx/tmp; SOURCE="test.pdf"; ILTYPE="plane" ; GEOMETRY="1240x1754"; QUALITY=90; DENSITY="150x150"; for OUT in "jpg" "png"; do echo $OUT; DEST="$SOURCE.%02d.$OUT"; convert +adjoin -interlace $ILTYPE -geometry $GEOMETRY \ -density $DENSITY -quality $QUALITY $SOURCE $DEST done

    Maybe some other installations like latex2html or GraphicsMagick are altering the behavior of convert on my box?

    Cheers Rolf

    PS: Große Vallüla ??? xD (SCNR)

    UPDATE: just noticed I didn't even use the -antialias switch ...

      Thanks, that's already a lot better (placing the -density option before the source file name seems to have caused the major improvement).

      Yet, I'm not really convinced of the quality that can be achieved that way. Maybe I'm little picky in these things, but I still feel the text looks a bit ragged, and the graphics don't seem to be anti-aliased at all (I also tried putting -antialias in various places — couldn't see a difference, though).  In other words, I can't help thinking that the results of running gs separately somehow look better (the version on the right in the side-by-side comparison (300%-zoom, cropped)) — at least smoother.  Anyhow, I guess I'll stick with my technique for the time being.


      PS: Große Vallüla ??? xD

      Yeah well, that was the first adequate PDF file I found in my temp directory.  Rest assured, I have no affiliation with Maria & Margot, or that kind of music, whatsoever ;) — I just like hiking in the mountains.

        Right, I remember reading somewhere that with convert switches order counts ...

        UPDATE< convert can process several files at a time, and the switches have to be before the corresponding filename! >

        > Yet, I'm not really convinced of the quality that can be achieved that way.

        UPDATE< Did you try a higher density yet? 300 works fine for me and filesize even drops!>

        Actually I switched 7 years ago to pstoimg from the latex2html distribution producing very neat png's.

        (but it's -as I noticed today - just a perl wrapper around gs ;)

        Anyway pstoimg has two switches for antialiasing : -antialias and -aaliastext so I suppose thats the point where convert may loose the necessary information...

        Cheers Rolf

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://794933]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2018-05-27 01:36 GMT
Find Nodes?
    Voting Booth?