#!/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"); #### #!/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");