Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-03-29 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found