in reply to Re^2: Splitting PDFs with PDF::API2
in thread Splitting PDFs with PDF::API2

Hi, I did create a new blank pdf from scratch using the PDF::Create module as a test and it worked.

Should my code look like this? (Notice change made to line 5)

#!/usr/bin/env perl use strict; use warnings; use PDF::API2; my $filename = shift || 'test.pdf'; my $oldpdf = PDF::API2->open(/downloads/YuruguOCR.pdf); my $newpdf = PDF::API2->new; for my $page_nb (1..$oldpdf->pages) { my ($page, @cropdata); $page = $newpdf->importpage($oldpdf, $page_nb); @cropdata = $page->get_mediabox; $cropdata[2] /= 2; $page->cropbox(@cropdata); $page->trimbox(@cropdata); $page->mediabox(@cropdata); $page = $newpdf->importpage($oldpdf, $page_nb); @cropdata = $page->get_mediabox; $cropdata[0] = $cropdata[2] / 2; $page->cropbox(@cropdata); $page->trimbox(@cropdata); $page->mediabox(@cropdata); } (my $newfilename = $filename) =~ s/(.*)\.(\w+)$/$1.clean.$2/; $newpdf->saveas('$newfilename'); __END__

Or should I have edited more lines?

Replies are listed 'Best First'.
Re^4: Splitting PDFs with PDF::API2
by perlron (Pilgrim) on Oct 29, 2014 at 19:18 UTC

    about line 5 So the open statement opens an existing PDF file.
    # Open an existing PDF file $pdf = PDF::API2->open('some.pdf');

    and to create a new pdf in the directory of your choice..
    $pdf = PDF::API2->new(-file => 'our/new.pdf');
    Please note PDF::API2 and PDF::Create are two different modules on CPAN. more info on the metacpan site

    The temporal difficulty with perl is u need to know C well to know its awesome.else u just keep *using* it and writing inefficient code