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

Hi Monks!
I need to build this little program to allow a user to enter the number or numbers of the page(s) from a multipage PDF document and I know it can be done using Ghostscript directly. For example, to extract pages 22-36 from a 100-page PDF file using pdftk:
$ pdftk A=100p-inputfile.pdf cat A22-36 output outfile_p22-p36.pdf

But is that a way to convert this into a user friendly program for users?
Thanks for the help!

Replies are listed 'Best First'.
Re: Extract certain pages from a multi page PDF doc help!
by zentara (Cardinal) on Oct 22, 2010 at 13:09 UTC
Re: Extract certain pages from a multi page PDF doc help!
by zentara (Cardinal) on Oct 22, 2010 at 14:09 UTC
    Just in case you were looking for an idea on how to make pdftk a bit more user friendly, you could take this as a start. Of course there are all sorts of details to account for, like input file name, extracting a single page, trying to extract an illegal range of pages, etc. etc. etc. But that is why writing a good gui takes some time and effort. :-)
    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = tkinit; my ($page_start,$page_end); $mw->Label(-text => 'Start' )->grid(-row => 0, -column => 0 +); $mw->Entry(-textvariable => \$page_start )->grid(-row => 0, -column + => 1); $mw->Label(-text => 'End' )->grid(-row => 1, -column => 0); $mw->Entry(-textvariable => \$page_end )->grid(-row => 1, -column => 1 +); my $bframe = $mw->Frame(-border => 1)->grid(); my $button = $bframe->Button(-text => 'Ok', -bg => 'hotpink', -command => \&get_pdfs )->grid(); MainLoop; sub get_pdfs{ print "Start $page_start \t\t End $page_end\n"; #untested string concantations, but you should get the idea # system ( pdftk A=100p-inputfile.pdf cat A22-36 output outfile_p22-p +36.pdf ) # system ( "pdftk A=100p-inputfile.pdf cat A.$page_start-$page_end ou +tput outfile_p$page_start-p$page_end.pdf ) print "Done\n"; }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      I did this one:
      #!/usr/bin/perl -w use strict; use PDF::Extract; my $pdf; $pdf=new PDF::Extract( PDFDoc=>"the.pdf"); $pdf->savePDFExtract(PDFPages=>"1 3", PDFCache=>"directory_to" );
Re: Extract certain pages from a multi page PDF doc help!
by Ratazong (Monsignor) on Oct 22, 2010 at 12:56 UTC

    You should distinguish between the "user friendly" frontend and the backend (doing the work).

    • For the frontend you could use any GUI you like, e.g. tk or some web-form ... whatever you find most user-friendly
    • In the backend you would just take the data from the frontend and use it to create a command similar to the one you mention in your question, and then execute it using system or backticks.
    HTH, Rata
Re: Extract certain pages from a multi page PDF doc help!
by shevek (Beadle) on Oct 23, 2010 at 10:04 UTC

    Hello, I cannot tell if you need a web UI or a traditional gui? Either way, I would use PDF::Extract from CPAN. Please go and read the doc on it. If you need a traditional GUI, I would use wxPerl. Cross-platform and has a native look and feel of the platform you are using.