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.


Reply via email to