lennelei has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I've a very small Perl script that splits PDF files bigger than 100 pages :
use strict; use warnings; use PDF::API2; #...some code here... #for testing purpose: my $file='path_to_some.pdf'; # my $oldpdf = PDF::API2->open($file); if ($oldpdf->pages > 100) { my $newpdf = PDF::API2->new; printf " (%d pages)\n", $oldpdf->pages; for my $page_nb (1..10) { $newpdf->importpage($oldpdf, $page_nb); } $newpdf->saveas("_$file"); }
I'm running this on Windows (Windows 7 for my desktop, Windows 2008/2012 for the servers) with a Strawberry Perl 5.14 and PDF::API2 module installed using cpan.bat
It's working and used for weeks now without trouble until this week. With a pdf received a few days ago, the script output is a 100 blank pages document.
I tried using the alternative with importPageIntoForm by snoopy from http://www.perlmonks.org/?node_id=615492 with the same result.
I also tried another tool (sejda) and the pages are correctly extracted so it's probably an issue with PDF::API2 or a misconfiguration but I don't know what to add/change in the script.
FYI, the sejda command line:
sejda-console.bat extractpages -f SOURCE.PDF -o TARGET.PDF -s 1-100Any idea/alternative I could try? I'd like to keep the Perl as this is only a small part of a bigger script, but if I have no other option, I'll use sejda for the split.
Unfortunately, I cannot provide the PDF :(
Thank you
Edit : I just found and tried with CAM::PDF using the following code and it's working!
For what I've seen, the difference between both code is that PDF::API2->import_page function tries to copy the content of the pages where CAM::PDF->extractPages function removes the pages outside the given range. Maybe there is a similar method in PDF::API2 but I couldn't find it yet?
use strict; use warnings; use CAM::PDF; #...some code here... #for testing purpose: my $file='path_to_some.pdf'; # my $oldpdf = CAM::PDF->new($file) or die "$CAM::PDF::errstr\n"; if ($oldpdf->numPages() > 100) { printf " (%d pages)\n", $oldpdf->numPages(); $oldpdf->extractPages(1..100); $oldpdf->cleanoutput("_$file"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: blank pdf generated using PDF::API2
by thanos1983 (Parson) on Jul 21, 2017 at 08:16 UTC | |
by poj (Abbot) on Jul 21, 2017 at 08:44 UTC | |
by thanos1983 (Parson) on Jul 21, 2017 at 09:10 UTC | |
by lennelei (Acolyte) on Jul 21, 2017 at 09:29 UTC | |
by thanos1983 (Parson) on Jul 21, 2017 at 09:36 UTC | |
by hippo (Archbishop) on Jul 21, 2017 at 09:47 UTC | |
by thanos1983 (Parson) on Jul 21, 2017 at 10:14 UTC | |
| |
by lennelei (Acolyte) on Jul 21, 2017 at 10:16 UTC | |
by AnomalousMonk (Archbishop) on Jul 21, 2017 at 10:53 UTC | |
| |
by thanos1983 (Parson) on Jul 21, 2017 at 10:50 UTC |