Hello esteemed monks,
I'm trying to create a PDF using PDF::API2. The resultant PDF needs to contain both text and a graphic on the same page, with the text printed over the top of the graphic. I'm using the following code, taken essentially straight from the PDF::API2 manpage:
use strict; use warnings; use DBI; use DBD::mysql; use PDF::API2; my $font_size=10; my $pdf = PDF::API2->new(-file => "mypdf.pdf"); $pdf->mediabox(595,842); my $page = $pdf->page; my $fnt = $pdf->corefont('Helvetica',-encode => 'latin1'); my $boldfont=$pdf->corefont('Helvetica-Bold',-encode => 'latin1'); my $txt = $page->hybrid; my $gfx=$page->gfx; $txt->textstart; $txt->font($boldfont,$font_size); $txt->translate(100,800); $txt->text("Heading here."); my $image=$pdf->image_jpeg('santa.jpg'); $gfx->image( $image, 100, 100 ); $txt->font($fnt, $font_size); $txt->translate(100,750); my $y=750; $txt->font($fnt, $font_size); my $dbh=DBI->connect("DBI:mysql:database=voice:host=localhost","userna +me","password") or die "$!\n"; my $sth=$dbh->prepare("select column1,column2,column3,column4,column5 +from test") or die "$!\n"; $sth->execute() or die "$!\n"; while (my @row=$sth->fetchrow_array()) { my $string=join(",",@row)."\n"; $txt->translate(100,$y); $txt->text("$string"); $y-=45; if ($y < 100 ) { $txt->textend; $page = $pdf->page(0); $txt = $page->hybrid; $txt->textstart; $txt->font($fnt, $font_size); $txt->translate(100,800); $y=750; $txt->textstart; $txt->font($boldfont,$font_size); $txt->text("Heading here."); $txt->font($fnt, $font_size); } } $sth->finish(); $dbh->disconnect(); $txt->textend; $pdf->save; $pdf->end( );
However, this puts the image on top of the text, and the text becomes unreadable. I need to be able to read the text. Given that I don't really understand the way PDFs work, can anybody point me in the right direction?

In reply to Putting text and images in PDFs using PDF::API2 by leighsharpe

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.