Jetzt kostenlos registrieren. Mitglieder surfen ohne Werbung auf Android-Hilfe.de!
Zurück   Android-Hilfe.de > Google Android OS > Android Apps > Business und Organisation

Perl-Script: PDF 2 Comic Book Archive Converter

Das Thema "Perl-Script: PDF 2 Comic Book Archive Converter" befindet sich unter Business und Organisation auf Android-Hilfe.de.


Antwort

 

Themen-Optionen Ansicht
Alt 25.03.2009, 00:10   #1 (permalink)
Neuer Benutzer

Registriert seit: 14.03.2009
Beiträge: 9
Abgegebene Danke: 0
Erhielt 1 Danke für 1 Beitrag
Beitrag Perl-Script: PDF 2 Comic Book Archive Converter

Ich finde den HTC-G1 eigentlich sehr praktisch, um sich Vortragsfolien anzuschauen. Leider gibt es jedoch noch keinen PDF-Reader, mit dem dies einfach möglich wäre. Ich habe deshalb ein Skript geschrieben, dass aus einer PDF-Datei ein Comic Book Archive erstellt - dass ist eine einfache ZIP-Datei, in der die einzelnen Seiten sortiert als Bitmaps (PNG oder JPEG) enthalten sind.

Ich suche noch einen Open Source Comic Reader für Android, fürs erste tut es auch zum Beispiel der ACV (Droid Comic Viewer) von robotcomics.net. Das Skript benötigt Perl und Ghostview, ich habe es bisher nur unter Linux getestet. Praktisch wäre noch eine Server-Variante, wo man einfach das PDF hinschickt und die CBZ/ACV/ZIP o.Ä. Datei zurückbekommt. Als Standard wird ein PDF mit A4 Querformat angenommen und 480x320 Pixel Bilder in PNG erzeugt, aber das lässt sich per Kommandozeilenparameter auch anders angeben.

Wenn übrigens etwas auf den Folien nicht lesbar ist, weil es zu klein ist, liegt das nicht am Skript oder an der Auflösung des HTC-G1 sondern daran, dass die Folien schlecht gestaltet wurden, weil zuviel zu kleiner Text darauf gepackt wurde anstatt höchstens 3-4 Listenpunkte.

PHP-Code:
#!/usr/bin/perl

=head1 NAME

pdf2comic 
convert pdf and postscript files to comic book archives

=cut

use strict;
use 
warnings;

use 
File::Temp qw(tempdir);
use 
File::Spec;

my $debug 1;

# parse command line parameters

my $force $ARGV[0] && $ARGV[0eq '-f' shift 0;
my $infile shift;
my $outfile shift;

(
$infile and -f $infile and $outfile
    or die(
"Usage: pdf2comic [-f] <pdf> <outfile> [options]");

(
not $force and -f $outfile)
    and die(
"output file already exists, use -f to overwrite");


my ($jpegq);
my $device "png16m";
my $ext "png";
my ($outx,$outy) = (480,320);     # output size in pixels
my ($width,$height) = (11.7,8.3); # paper size in inch

foreach (@ARGV) {
    if ( 
$_ =~ /^png$/) {  # png, jpg, jpeg
        
$device "png16m"$ext "png";
    } 
elsif$_ =~ /^jpe?g$/) {
        
$device "jpeg"$ext "jpg";
    } 
elsif$_ =~ /^(\d+)%$/ ) { # n% : JPEG quality
        
$jpegq = $if $and $<= 100;
    } 
elsif$_ =~ /^(\d+)x(\d+)$/) { # output size in pixels
        
($outx,$outy) = ($1,$2) if $and $0;
    } 
elsif$_ =~ /^a4$/) {
        (
$width,$height) = (11.7,8.3); # A4 format
    
elsif$_ =~ /^letter$/) {
        (
$width,$height) = (11.0,8.5); # letter format
    
}
    
# TODO: color depth (png16,png16m,png256)
    # TODO: Anti-aliasing (1=off,2,4)
}

# initialize

my $tempdir tempdirCLEANUP => );
my $filepattern 'page%03d.'.$ext;

# Anti-aliasing (1=off,2,4)
my $aa 4

my @params;
push @params"-SDEVICE=$device";

# output size and resulution in pixels per inch
push @paramssprintf('-g%dx%d',$outx,$outy);
push @paramssprintf('-r%0.2fx%0.2f'$outx/$width$outy/$height);

# anti-aliasing
push @params"-dTextAlphaBits=$aa""-dGraphicsAlphaBits=$aa";

# JPEG Quality
push @params"-dJPEGQ=$jpegqif $jpegq;

# output and input file
push @params"-sOutputFile=$tempdir/$filepattern";
push @params"-dNOPAUSE""-dBATCH""--"$infile;


# run

print join("\n",@params) . "\n" if $debug;
system('gs',@params) == or die("Failed to convert with ghostscript");

my $cwd File::Spec->rel2abs(File::Spec->curdir());
chdir $tempdir;
my @files = <*>;

system (qw{zip --D}, File::Spec->rel2abs($outfile,$cwd), @files) == 0
    
or die("Failed to create zip file");

print 
"created $outfile\n";

=
head1 DESCRIPTION

This script converts a PDF document into a comic book archive file 
that
is an archive of sequentially sorted image files
The script depends on
ghostscript 
and zip which must be on your environment.

pdf2comic was created to PDF files to easily view slides on a HTC-G1 mobile
device
but you can convert any other PDFBy default a resolution of 320x480
is used 
for output and A4 paper size for inputThe HTC-G1 has a 3,2" display
with 180ppi so you should at least use 20pt font size.

=head1 EXAMPLES

Default settings, create zip file
  pdf2comic myslides.pdf myslides.zip

JPEG 90% quality, create cvz file
  pdf2comic myslides.pdf myslides.cbz jpeg 90%

Slides in A4, create PNGs high resolution acv file
  pdf2comic myslides.pdf myslides.acv 920x640 png a4

=head1 TODO

The paper size could automatically be determined because it is stored
in the PDF/PS file. This way we could also handle different orientation.

Support rar archives (cbr) in not included yet.

=head1 LICENSE

This is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available. 

Geändert von zx128 (26.03.2009 um 10:46 Uhr)
jakob ist offline   Mit Zitat antworten
Alt 25.03.2009, 23:18   #2 (permalink)
Android-Hilfe.de Mitglied

Registriert seit: 03.02.2009
Beiträge: 140
Abgegebene Danke: 0
Erhielt 1 Danke für 1 Beitrag
Standard AW: Vortragsfolien und andere PDF lesen unter Android

Also um PDFs zu lesen, kann man Jetced PDF benutzen. Damit kann man auch Zoomen.
gadiator ist offline   Mit Zitat antworten
Antwort

Stichworte
pdf

Themen-Optionen
Ansicht


Ähnliche Themen

Thema Autor Forum Antworten Letzter Beitrag
Themes Converter Screamat Android Themes 1 09.04.2009 10:37
Suche PDF und Comic Reader .sorasonic Business und Organisation 0 09.02.2009 20:51




Du liest gerade: "Perl-Script: PDF 2 Comic Book Archive Converter" unter "Business und Organisation" auf Android-Hilfe.de.


Powered by vBulletin®
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO
© Android-Hilfe.de 2012 - All rights reserved.