Nelius,
This post belongs on the
perl-text-pdf-modules-hHKSG33TihhbjbujkaE4pw@xxxxxxxxxxxxxxxx list
rather than the Mac OS-X Perl list. I've cross posted it there and
would suggest that you subscribe to that list for all your PDF::API2
help. It's an active and helpful list.
You need to be calling the methods on objects and not on their class.
Once you open the PDF, you need to add the page to it rather than just
adding a page to ... a class.
The following code (from my head so it could be wrong) demonstrates how
you'd do it:
my $pdf = PDF::API2->open( $path_to_pdf ); # Open a PDF
my $page = $pdf->page( $pdf->pages ); # Add a page at the end
$page->do_something() # Do stuff to the page
If there's any PDF::API2ers reading this, feel free to correct my code.
Cheers!
Rick
On 15 Jun 2004, at 7:08 AM, Nelius Bresnan wrote:
> I'm a Perl novice using the PDF::API package to add stuff to the end
> of a
> PDF file. I've RTFMed, I've googled this and I even tried emailing the
> author but I'm totally stuck.
>
> I want to use the method PDF::API2::PDF::Page->add($str). At first I
> tried
> PDF::API2->page($index). This inserts-and-returns a new page at $index
> and
> it works fine. However an attempt to use $page->add($str) gets the
> error
> message:
> Can't locate object method "add" via package "PDF::API2::Page"
>
> So it seems that the scalar returned by PDF::API2->page is not the
> same kind
> of object that PDF::API2::PDF::Page->add is supposed to be called on.
> This
> surprised me - I expected both 'page' objects to be the same type. But
> I
> checked and there is a file /Library/Perl/5.8.1/PDF/API2/Page.pm and
> also a
> file /Library/Perl/5.8.1/PDF/API2/pdf/Page.pm so it would appear there
> are
> in fact two different kind of page objects. And AFAICT I need the
> other one.
>
> So I tried to create a scalar of type PDF::API2::PDF::Page using its
> constructor. But to create that I need an object of type
> PDF::API2::PDF::Pages to base it on. The constructor for Pages is
> PDF::API2::PDF::Pages->new($pdfs,$parent). But the explanation
> (http://cpan.uwinnipeg.ca/htdocs/PDF-API2/PDF/API2/PDF/Pages.html) of
> the
> parameters needed for $pdfs and $parent aren't explicit enough for a
> Perl
> novice like myself. It says that $parent should point at the file
> context if
> we're trying to create a root node. And I think thats what I need to
> do to
> add pages onto the end of the PDF file.
>
> I know enough Perl to know that contexts are very important in Perl.
> So I
> looked it up in three different manuals but none of them make any
> reference
> to a file context. So I'm assuming that context isn't being using in
> the
> canonical sense here and that the author simply means a file pointer
> of some
> kind.
>
> So I've supplied the $pdf scalar that was returned from
> PDF::API2->open('aPDFfile.pdf'). The pod says that "$pdfs is the file
> object
> (or objects) in which to create the new Pages object." I'm not sure
> precisely what it means by that but I think its that this is the file
> that
> it'll output to. I want it to output to the same file so I've provided
> the
> same $pdf value again. So my attempted construction of a 'pages' object
> looks like this:
> my $pages = PDF::API2::PDF::Pages->new($pdf, $pdf);
>
> when I run it it craps out giving the message:
> Can't locate object method "new_obj" via package "PDF::API2" at
> /Library/Perl/5.8.1/PDF/API2/PDF/Pages.pm line 68.
> I had a look at the line in question and its pretty hairy stuff. I
> think its
> doing something about creating a file outputstream or something like
> that.
> It's expecting that there will be a pointer to an object in $_ and I
> think
> its the wrong kind of object and consequently it can't find the
> method. But
> I'm (way) out of my depth. I think my problem is that my providing the
> wrong
> parameters to PDF::API2::PDF::Pages->new. But I just can't understand
> what I
> should be giving it. The POD comments are too vague for me. I don't
> get what
> I should be providing to it.
>
> thank you.
>
> Nelius Bresnan.
>
>
>
Senior Developer
PrintSupply - Print Procurement & Supply Management
18 Greenaway Street VIC 3105
Tel: (03) 9850 3255
Fx: (03) 9850 3277
http://www.printsupply.com.au/
------------------------ Yahoo! Groups Sponsor --------------------~-->
Yahoo! Domains - Claim yours for only $14.70
http://us.click.yahoo.com/Z1wmxD/DREIAA/yQLSAA/dpFolB/TM
--------------------------------------------------------------------~->
To unsubscribe from this group, send an email to:
perl-text-pdf-modules-unsubscribe-Km8ibD4bFueDmjp1MlKEbA@xxxxxxxxxxxxxxxx
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/perl-text-pdf-modules/
<*> To unsubscribe from this group, send an email to:
perl-text-pdf-modules-unsubscribe-hHKSG33TihhbjbujkaE4pw@xxxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|