How do I use CAM::PDF::Annot (perl module) without erroring?
I have been trying to use CAM:PDF::Annot for it's most basic purpose, agg开发者_Python百科regating the annotations of two pdf's, but have not had any success.
I have been trying to emulate what is in the package's synopsis on CPAN, but keep coming up with an error.
The code in the CPAN synopsis (as a completed script), or any advice would be helpful.
CPAN page: http://metacpan.org/pod/CAM::PDF::Annot
So far I have:
#!/usr/bin/perl
use strict
use CAM::PDF;
use CAM::PDF::Annot;
sub main()
{
my $pdf = CAM::PDF::Annot->new( 'testAnnotPDF.pdf' );
my $otherDoc = CAM::PDF::Annot->new( 'testAnnotPDF2.pdf' );
my $page = 1;
my %refs;
my $hrefs = \%refs;
for my $annotRef (@{$pdf->getAnnotations($page)}){
$otherDoc->appendAnnotation( $page, $pdf, $annotRef, $hrefs );
}
$otherDoc->output('pdf_merged.pdf');
}
exit main;
Well, the getAnnotations()
method appears to return an array reference, whereas the appendAnnotation()
method takes an annotation object and not an array reference. Try doing what the documetation says:
for my $annotRef ( @{$pdf->getAnnotations( $page )} ) {
$otherDoc->appendAnnotation( $page, $pdf, $annotRef, \%refs );
}
You're not looping over all of the annotation references that you get back from getAnnotations()
, you're just trying to stick the full array reference in there, and that's not going to work.
精彩评论