Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

when I save a PDF document with this code:

print "open the original document \n"; my $pdf1 = CAM::PDF->new($doc1); print "save it to the new location \n"; $pdf1->output($newdoc1);

I get no errors. However if I use this code:

print "open the original document \n"; my $pdf1 = CAM::PDF->new($doc1); print "save it to the new location \n"; $pdf1->cleanoutput($newdoc1);

I get this error:

Bad request for object 1121 at position 0 in the file Use of uninitialized value in string eq at C:/Dwimperl/perl/site/lib/C +AM/PDF.pm line 4898. Not a ref at C:/Dwimperl/perl/site/lib/CAM/PDF.pm line 5273.

In case it is helpful, the getPrefs method returns this list

[ [0] undef, [1] undef, [2] 1, [3] 1, [4] 1, [5] 1 ]

Doc1 is a PDF document that opens OK in Adobe reader and professional.

Replies are listed 'Best First'.
Re: CAM::PDF cleanoutput Error
by GotToBTru (Prior) on Nov 25, 2014 at 15:57 UTC

    Did the new() method succeed? Is the value of $newdoc1 what you think it is?

    1 Peter 4:10

      I have coded this:

      if (!$pdf1) { print "Create PDF failed \n"; GETOUT; }

      Where the subroutine GETOUT does some graceful shut down but the code is never executed. I also tried eval with the same non-result.

      So, it seems the ->new() method returns something and, in the case of the ->output() method, it appears to be something CAM::PDF knows about.

      Also, even though ->output works in the first case, if I use ->appendPDF later in the code and try to save the result the ->output method will fail with the same error.

        Perhaps the output functions clear out the document in memory? The docs don't explicitly say that, but it seems to match what you are observing.

        1 Peter 4:10
Re: CAM::PDF cleanoutput Error
by Anonymous Monk on Nov 25, 2014 at 15:53 UTC

    Also, other PDFs from the same source do not exhibit this issue. Most load and save without issue.