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

Hi,
I've got a PDF file, and I want to send just one page (p. 45) from that (rather large) pdf document to a friend.

So ... I installed PDF-API2-2.020 and ran the following code based on an example from the docs (which, I think, should create a valid pdf file that contains just that one page):
use strict; use warnings; use PDF::API2; my $pdf = PDF::API2->new(); my $old = PDF::API2->open('C:/_32/Peugeot/Chapter_01_engine.pdf'); my $count = $old->pages(); print "Original document contains 138 pages (according to Adobe)\n"; print "Original document contains $count pages (according to PDF::API2 +)\n"; # Add page 45 from the old PDF as page 1 of the new PDF my $page = $pdf->importpage($old, 45); print "\$page: $page\n"; $count = $pdf->pages(); print "New pdf doc contains $count pages\n"; $pdf->saveas('C:/_32/Peugeot/head.pdf');
When I run that script, it ouptuts:
Original document contains 138 pages (according to Adobe) Original document contains 138 pages (according to PDF::API2) $page: PDF::API2::Page=HASH(0x321bc24) New pdf doc contains 1 pages
And it creates a new pdf document (head.pdf) that contains one page.
Unfortunately that one page is blank (though page 45 from the original pdf file contains both text and images).

What's going wrong here ?
I've tried the same thing on both Windows 7 (perl-5.16.0) and debian wheezy (perl-5.18.2), and it's the same result.

UPDATE: When I examine the security details of the original pdf file, I see "Page Extraction: Not Allowed" .... maybe that has something to do with the problem ?

Cheers,
Rob

Replies are listed 'Best First'.
Re: [PDF::API2] How to import a page
by Anonymous Monk on Feb 18, 2014 at 05:52 UTC
      Maybe, try http://search.cpan.org/dist/CAM-PDF/bin/getpdftext.pl to see if it can help

      I wanted the entire page (not just the text content).

      It didn't occur to me that the provider of the pdf file from which I wish to copy the page might have put such settings in place ... I probably ought to respect his intentions.
      I've just tried the script with another pdf file that doesn't have any security settings - and the script then works fine.

      Cheers,
      Rob