Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by LanX (Canon)
on Sep 12, 2009 at 14:13 UTC ( #794928=note: print w/ replies, xml ) Need Help??


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

Almut, IIRC convert has a switch for antialiasing, I never had problems converting PDF to bitmaps (well ... years ago)

So no need for oversampling.

Cheers Rolf


Comment on Re^2: Convert PDF to HTML (or JPEG)
Download Code
Re^3: Convert PDF to HTML (or JPEG)
by almut (Canon) on Sep 12, 2009 at 17:33 UTC

    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 :)

      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!

      test.pdf.00.jpg

      test.pdf.00.png

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://794928]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2014-07-22 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (110 votes), past polls