Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: PDF-API2 Basic Question

by edoc (Chaplain)
on May 10, 2005 at 02:37 UTC ( #455400=note: print w/replies, xml ) Need Help??


in reply to PDF-API2 Basic Question

When I ran your code it produced a document with two pages but the page labels were both on the first page. You need to get a text object from the 2nd page so you can add text to it. The text object you are using is from the first page so that's where the text goes.

#!c:/perl/bin/perl -w use strict; use PDF::API2; my $pdf=PDF::API2->new; # Create a new top-level PDF document my $font = $pdf->corefont('Helvetica'); my ($page, $text); $page=$pdf->page(); # Create 1st page $page->mediabox(500, 700); # Set the page dimensions $text=$page->text(); $text->translate(50, 650); # Position the text $text->font($font,12); $text->text("Page 1"); $page=$pdf->page(); # Create 2nd page $page->mediabox(500, 700); # Set the page dimensions $text = $page->text(); $text->translate(50, 650); # Position the text $text->font($font,12); $text->text("Page 2"); $pdf->saveas("file.pdf"); $pdf->end; exit;

cheers,

J

Replies are listed 'Best First'.
Re^2: PDF-API2 Basic Question
by jstrat (Initiate) on May 14, 2005 at 02:33 UTC
    I agree with you. I need to creat a text object for the 2nd page, but when I try I receive this error:
    Can't call method "isvirtual" on an undefined value at C:/Perl/site/li +b/PDF/API2 /Content.pm line 1456.
    This is the code I am using:
    #!c:/perl/bin/perl -w use strict; use PDF::API2; my $pdf=PDF::API2->new; # Create a new top-level PDF document my $font = $pdf->corefont('Helvetica'); my ($page, $text); $page=$pdf->page(); # Create 1st page $page->mediabox(500, 700); # Set the page dimensions $text=$page->text(); $text->translate(50, 650); # Position the text $text->font($font,12); $text->text("Page 1"); $page=$pdf->page(); # Create 2nd page $page->mediabox(500, 700); # Set the page dimensions my $text2=$page->text(); $text2->translate(50, 640); # Position the text $text2->text("Page 2"); $pdf->saveas("file.pdf"); $pdf->end; exit;

      The following code works. You need to define the media size and the font on the 2nd page.

      #!/usr/bin/perl -w use strict; use PDF::API2; my $pdf=PDF::API2->new; # Create a new top-level PDF document my $font = $pdf->corefont('Helvetica'); my ($page, $text); $page=$pdf->page(); # Create 1st page $page->mediabox(500, 700); # Set the page dimensions $text=$page->text(); $text->translate(50, 650); # Position the text $text->font($font,12); $text->text("Page 1"); $page=$pdf->page(2); # Create 2nd page $page=$pdf->openpage(2); $page->mediabox(500, 700); # Set the page dimensions for 2nd page $text=$page->text(); $text->font($font,12); # Set font on the 2nd page $text->translate(50, 640); # Position the text $text->text("Page 2"); $pdf->saveas("file.pdf"); $pdf->end;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://455400]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (1)
As of 2022-01-26 04:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (69 votes). Check out past polls.

    Notices?