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 :)


In reply to Re: PDF with Background Image VIA Perl by almut
in thread PDF with Background Image VIA Perl by Hammy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.