G'day James,

I used the following to create a minimal, 9-page, PDF document:

#!/usr/bin/env perl use strict; use warnings; use PDF::API2; my $pdf = PDF::API2::->new(); my $font = $pdf->font('Helvetica-Bold'); for my $content ('A' .. 'I') { my $page = $pdf->page(); my $text = $page->text(); $text->font($font, 20); $text->position(200, 700); $text->text($content); } $pdf->save('DX.pdf');

A visual check of "DX.pdf", with Foxit Reader, showed nine pages with "A", "B", ..., "H", "I".

I pretty much copied your posted code. Here's my exact script:

#!/usr/bin/env perl use strict; use warnings; use CAM::PDF; my $pdf = CAM::PDF->new('DX.pdf'); my $np = $pdf->numPages(); print "Number of pages: $np\n"; $pdf->extractPages( 2..8 ); $pdf->cleanoutput('DXout.pdf');

When I ran this, the only output was:

Number of pages: 9

A visual check of "DXout.pdf", with Foxit Reader, showed seven pages with "B", ..., "H".

So, your code is behaving as expected. This suggests a problem with your source PDF. There could also be a problem with CAM::PDF itself: there are currently 52 active bugs; I did a quick scan but didn't see anything obvious; you may want to look more closely; updating to the latest version might be warranted.

Thanks for posting your environment information. I'm using Cygwin on Win10 (both updated less than 24 hours ago); Perl 5.36.0 (via Perlbrew); CAM::PDF 1.60 (latest version, newly installed as I haven't used that module previously); PDF::API2 2.043 (that's what I had, latest is 2.044).

As an afterthought, I did `perlbrew switch perl-5.34.0` and repeated the above tests. I got the same successful results: your Perl version doesn't appear to be an issue.

For your PDF::API2 installation issue, I suggest you post that separately and include verbatim error & warning messages.

— Ken


In reply to Re: CAM::PDF Error: Expected identifier label by kcott
in thread CAM::PDF Error: Expected identifier label by jmlynesjr

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.