[gull] perl pdf::api2, méthode image
Marc SCHAEFER
schaefer at alphanet.ch
Sat Oct 28 13:10:00 CEST 2006
On Sun, Oct 15, 2006 at 05:51:19PM +0200, Amel Kapetanovic wrote:
> Je ne comprends pas quelque-chose avec le script suivant :
Après avoir installé le package `libpdf-api2-perl', puis fait un
man PDF::API2, j'ai trouvé:
IMAGE METHODS
[ ... ]
$jpeg = $pdf->image_jpeg $file
Returns a new jpeg image object.
$tiff = $pdf->image_tiff $file
Returns a new tiff image object.
$pnm = $pdf->image_pnm $file
Returns a new pnm image object.
$png = $pdf->image_png $file
Returns a new png image object.
$gif = $pdf->image_gif $file
Returns a new gif image object.
$gdf = $pdf->image_gd $gdobj, %options
Returns a new image object from GD::Image.
[ ... ]
le script adapté suit
(dans mon cas utilisation d'un fichier PNG, car GIF est encombré de
brevets)
Il faudrait encore s'occuper du traitement d'erreurs.
#! /usr/bin/perl -w
# NOTES
# - Dependancies
# libpdf-api2-perl
# BUGS
# - Error detection/recovery very weak
# choose between exceptions or error_reason.
# TODO
use strict;
use PDF::API2;
my $pdf = new PDF::API2;
if (defined($pdf)) {
$pdf->mediabox('A4');
my $page = $pdf->page;
if (defined($page)) {
my $gfx = $page->gfx;
if (defined($gfx)) {
my $png = $pdf->image_png('/data/home/twiki/public_html/pub/Main/NF/alphanet.png');
if (defined($png)) {
$gfx->image($png,100,100);
$gfx->close; # BUGS: error checking ?
$pdf->saveas("logo.pdf"); # BUGS: error checking ?
$pdf->end; # BUGS: error checking and error flow?
exit(0);
}
else {
print "png\n";
}
}
else {
print "$gfx\n";
}
}
else {
print "page\n";
}
}
else {
print "pdf\n";
}
exit(1); # FAILURE
More information about the gull
mailing list