Hi - I have a problem where sometimes this method will cause the script to fail with the error "Can't upgrade that kind of scalar at /usr/lib/perl5/site_perl/5.8.8/PDF/API2/Basic/PDF/Objind.pm line 150", This will always happen with the same source PDF in the same job. Basically I'm doing :
use strict; use PDF::API2; my $source_pdf = $ARGV[0]; my $dest_pdf = $ARGV[1]; my $pdf_d = PDF::API2->new(); my $pdf_s = PDF::API2->open($source_pdf); for ( my $pdf_page = 1 ; $pdf_page <= $pdf_s->pages ; $pdf_page++ ){ my $pdf_d_page = $pdf_d->page(); my $pdf_d_pageform = $pdf_d->importPageIntoForm($pdf_s, $pdf_page); my $pdf_d_gfx = $pdf_d_page->gfx; $pdf_d_gfx->formimage($pdf_d_pageform, 0, 0, 1); } $pdf_s->end(); $pdf_d->saveas($dest_pdf); $pdf_d->end();
except that there is a lot of other code and all of the above is in several other loops etc. There're a lot of source pdfs. The "$pdf_s->end();" will cause the error in the bad cases.

I'm afraid that I'm unable to supply the actual code or the source, problem pdfs.

While I can duplicate this 100% when it happens (perhaps with 1 in 100,000 source pdfs) with the actual script and I have isolated that the "$pdf_s->end()" is the problem line, I have not been able to replicate it in smaller test scripts using the same source pdfs yet. However I have found that if I replace the $pdf_s->end() with undef($pdf_s) everything seems to go perfectly in the production script with the problem source pdfs.

So I ask for your wisdom, Monks. Is replacing $pdf_s->end() as described a bad idea for some reason that I'm unaware of? Thanks.

In reply to PDF::API2, $pdf->end by Tharg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.