Yes, I noticed that- saveas() does not return on success. PDF::API2 works well for this procedure on a few machines- but it fails on my i386. I tried CAM::PDF as you suggested.. I had to force install it via cpan. This is the example:
#!/usr/bin/perl use strict; use CAM::PDF; my $file_in = $ARGV[0]; my $prepend = $ARGV[1]; $prepend ||= 'out'; my $pdf = CAM::PDF->new($file_in); my $count = $pdf->numPages; undef $pdf; for my $i ( 0 .. ( $count - 1 )){ my $_i = ($i+1); my $file_out = sprintf "%s_page_%04d.pdf", $file_in, $_i; # make sure it's not there unlink $file_out; my $pdf = CAM::PDF->new($file_in); $pdf->extractPages($_i); $pdf->cleansave; $pdf->output($file_out); print STDERR "saved $file_out\n"; } exit;

It works. Slowly. You can see I am re-instancing a whole new pdf object for each one page I want. So, it the pdf has 110 pages, I have to re-instance 110 times, one for each page.

I can't figure out another way right now with CAM::PDF.

I really wish the documentation were a little bit better for these modules, PDF::API2 and CAM::PDF- and what's with the naming all the methods different? like numPages() and pages()- the interface is an inconsistency from hell- I don't care how much they worked on this- the messy api is unforgiveable.


In reply to Re^2: PDF::API2 importpage problem by leocharre
in thread PDF::API2 importpage problem by leocharre

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.