Hi monks,

I'm trying to produce a PDF with an image and many paragraphs of text. The code I've written has the same problem with both modules for the text, presumably because I'm making the same mistake.

First is there any good online documentation for either of these ? I've looked but can't find it.

The main problem is that long strings of text do not wrap, but instead disappear off the RHS of the page. escaped characters also make no difference. I've included my code below to demonstrate.

With PDF:API2 I also can't get the graphic to appear (see podded out code below). I get the following error

Can't call method "val" on an undefined value at ...../PDF/API2/Resource/XObject/Image.pm line 99

Finally, is there a way to centralise/align the heading (not included in CreateSimple version of PDF) ?

Thanks.
use PDF::CreateSimple; use strict; use warnings; my $filename = "./test"; my $string = "hello there. This is a fairly long line containing lots +of utterly meaningless long-winded text that I would really realy rea +lly like to see wrapping onto the line below rather than just disapp +earing off the edge of the page.\nThis is still more on a second line +"; my $font_size=10; my $pdf = PDF::API2->new(-file => "mypdf.pdf"); my $page = $pdf->page; my $fnt = $pdf->corefont('Helvetica',-encode => 'latin1'); my $boldfont=$pdf->corefont('Helvetica-Bold',-encode => 'latin1'); my $txt = $page->text; #Heading needs to be centralised $txt->textstart; $txt->font($boldfont,$font_size); $txt->translate(100,770); $txt->text("Heading here."); $txt->textend; =pod #commented out graphic code $pdf->mediabox(595,842); my $gfx=$page->gfx; my $image=$pdf->image_jpeg('./logo.gif'); $gfx->image( $image, 100, 100 ); =cut #String does appear but incorrectly formatted $txt->textstart; $txt->font($fnt, $font_size); $txt->translate(50,670); $txt->text("$string"); $txt->textend; $pdf->save; $pdf->end( ); #------------------------------------------------------ # Try it with PDF::CreateSimple #------------------------------------------------------ my $pdfFile = PDF::CreateSimple->new("./pdfcs.pdf"); $pdfFile->drawText("$string",'Verdana',12,200,760,'black'); $pdfFile->drawImage('./logo.gif',150,650,1.75); $pdfFile->closeFile;

In reply to PDF::API2 and PDF::CreateSimple by u671296

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.