You might have shown us what you've tried so far :)
(You know,
your fellow Monks are always more inclined to point out deficiencies
in your code, than write the code from scratch themselves... OK, just kidding).
Anyway, here are two examples using PDF::API2 that should
get you started:
#!/usr/bin/perl
use strict;
use warnings;
use PDF::API2;
my $text = "Some text on top of the image";
my $pdf = PDF::API2->new();
my $page = $pdf->page;
# note, the order of the next two statements is IMPORTANT
# (otherwise the image will be rendered on top of the text, hiding it.
+..)
my $gfx = $page->gfx;
my $txt = $page->text;
my $img = $pdf->image_jpeg("background.jpg");
$gfx->image( $img,
30, 100, # position (by default in points (=1/72 inch))
0.5 # scaling (i.e. size)
# (you'll probably want to play with those...)
);
my $font = $pdf->corefont('Helvetica-Bold', -encoding => 'latin1');
# alternatively, use TrueType fonts:
# my $font = $pdf->ttfont('Verdana-Bold.ttf', -encoding => 'latin1');
$txt->font($font, 25);
$txt->translate(100, 150);
$txt->fillcolor('white');
$txt->text($text);
$pdf->saveas("Test1.pdf");
The next example makes use of the textlabel() method, which
might be more convenient if you have several short text fragments you'd
like to position / configure individually.
#!/usr/bin/perl
use strict;
use warnings;
use PDF::API2;
my $text = "Some text on top of the image";
my $pdf = PDF::API2->new();
my $page = $pdf->page;
my $gfx = $page->gfx;
my $img = $pdf->image_jpeg("background.jpg");
$gfx->image( $img,
30, 100, # position (by default in points (=1/72 inch))
0.5 # scaling (i.e. size)
# (you'll probably want to play with those...)
);
my $font = $pdf->corefont('Helvetica-Bold', -encoding => 'latin1');
$gfx->textlabel(
100, 100, # position (in points)
$font, 30, # font and size
$text, # guess what...
# options
-color => '#ff0080', # in pink ;)
-rotate => 30, # angle
);
$pdf->saveas("Test2.pdf");
Also, be sure to read the docs of PDF::API2::Content (in
addition to PDF::API2). It contains the interesting stuff :)
|