Have look at
http://www.pdflib.com/
Its a general library which has bindings for C, C++, Java, ... and
Perl.
I tested under MacPerl and it works fine.
A sample of mine follows below.
Note that a new version is arriving which has the very nice feature
to have a PDF template file where you can just copy objects from.
Axel
(excuse the german comments ...)
#!/usr/bin/perl
# image.pl
# Copyright (C) 1997-2000 Thomas Merz. All rights reserved.
#
# PDFlib client: image example in Perl
#
use File::Spec::Functions;
use lib ':';
use pdflib_pl 3.02;
init();
$imagefile = catfile(updir, "images", "nesrin.jpg" );
die "imagefile '$imagefile' not readable: $^E\n" unless -r $imagefile;
$p = PDF_new() or die "could not create new pdf object\n";
# sollte gehen, will aber nicht
# print "DEBUG curdir = ", curdir, "\n";
# die "Couldn't open PDF file" if (PDF_open_file($p, catfile( curdir,
"image+text_pl.pdf" ) ) == -1);
### workaround ###
(PDF_open_file($p, catfile( "Festplatte:image+text_pl.pdf" ) ) == -1) and die
"Couldn't open PDF file: $!";
$font = PDF_findfont($p, "Helvetica-Bold", "host", 0);
PDF_set_info($p, "Creator", "image.pl");
PDF_set_info($p, "Author", "Thomas Merz");
PDF_set_info($p, "Title", "image sample (Perl)");
# Datei im gleichen Verzeichnis oder relativer Pfad funktioniert hier nicht
# egal ob Mac oder Unix Verzeichnistrenner
### workaround ###
$imagefile = "Festplatte:nesrin.jpg";
$image = PDF_open_image_file($p, "jpeg", $imagefile, "", 0);
die "Couldn't open image '$imagefile'" if ($image == -1);
# We generate a page with the image's dimensions
$width = PDF_get_value($p, "imagewidth", $image);
$height = PDF_get_value($p, "imageheight", $image);
PDF_begin_page($p, $width, $height);
# das Bild
PDF_place_image($p, $image, 0, 0, 1);
# ein wenig Text über das Bild
PDF_setfont($p, $font, 18.0);
PDF_set_text_pos($p, 20, $height-20);
PDF_show($p, "Hello world!");
PDF_continue_text($p, "(says Perl)");
&longt();
PDF_end_page($p);
END
{
if( $p )
{
PDF_close($p);
PDF_delete($p)
}
if( $pp )
{
PDF_close($pp);
PDF_delete($pp)
}
}
sub longt
{
my( $x, $y ) = ( 0, 0);
my( $pp ) = PDF_new();
die "cound not create \$pp\n" unless $pp;
(PDF_open_file($pp, "" ) == -1) and die "Couldn't open PDF file: $!";
PDF_begin_page( $pp, 800, 800 );
my( $font ) = PDF_findfont( $pp, "Helvetica", "host", 0 );
PDF_setrgbcolor($pp, 1.0, 1.0, 1.0);
PDF_setfont($pp, $font, 10.0);
$x = PDF_get_value( $pp, "textx", "" );
print "before show_boxed() x = $x\n";
# llx, lly, width, height
PDF_show_boxed( $pp, $long_text, 0, 0, 200, 200, "left", "");
$x = PDF_get_value( $pp, "textx", "" );
print "before show_boxed() x = $x\n";
PDF_end_page( $pp );
}
sub init
{
$long_text = <<EOT;
Wir sind die Getreuen des persischen Volks,
Das zumal auszog zum hellenischen Land,
Sind Wächter der vielglückseligen und
Goldprangenden Sitze, die Xerxes selbst,
Mein König und Herr,
Auswählte, der Lande zu wachen.
EOT
}
--
----------------------------------------------------------------------
Axel Rose, Springer & Jacoby Digital GmbH & Co. KG, mailto:[EMAIL PROTECTED]
pub PGP key 1024/A21CB825 E0E4 BC69 E001 96E9 2EFD 86CA 9CA1 AAC5
"... denn alles, was entsteht, ist wert, daß es zugrunde geht ..."