View Single Post
Old 05-18-2010, 07:23 PM   #8
kidtwisted
Member
kidtwisted began at the beginning.
 
kidtwisted's Avatar
 
Posts: 16
Karma: 10
Join Date: May 2010
Location: Southern California
Device: JetBook-Lite
Quote:
Originally Posted by syrex314 View Post
One thing that bugs me about the JB is that some PDFs render in an ugly, pixellated way. So for those who have Linux, I wrote a perl script that takes a PDF, and uses ImageMagick to antialias and rescale the pages for the native size of the Jetbook's screen. This is provided AS-IS, and I'm sure other software does a better job, but hey-- some of you might find it useful.

Code:
#!/usr/bin/perl
#
# pdfToPpmToPdf.pl
#
# A perl script to convert a PDF to a series of PPM files, one per
# page, then back to PDF. 
#

# file names
$inPdfFileName = "in.pdf";
$outPdfFileName = "out.pdf";
$ppmRoot = "./tmp/page";

print "converting pages to images\n";

# call pdftoppm
system( "pdftoppm", "-gray", $inPdfFileName, $ppmRoot ) == 0
# and handle an error
# this could be improved by checking the error codes listed in the
# pdftoppm manpage
    or die "pdftoppm failed: $?";

print "converting each page to pdf\n";
# convert each page to a pdf
@files = <./tmp/*.pgm>;

foreach $file (@files) {
    $file =~ /(.+)\.pgm/;    # get filename in front of prefix
    print "processing image file $file\n";

    system("mogrify","-antialias","-trim","-resize", "460", $file) == 0
	or die "mogrify failed: $?";

    print "converting $file to $1.pdf\n";

    system( "convert", $file, "$1.pdf" ) == 0
	or die "convert to pdf failed: $?";
}

print "concatenating pdf pages\n";
# concatenate pages with ImageMagic's convert function
system("convert", "./tmp/*.pdf", "out.pdf" ) == 0
	or die "concatenate pdf failed: $?";
WOW, thanks for sharing your script. I'm adding it to my toolbox.
kidtwisted is offline   Reply With Quote