Since pdftotext defaults to inserting form feed characters between pages, you can examine each line for a form feed character as an indication of pagination:
use strict;
use warnings;
my $i = 0;
my $pageNum = 1;
open my $fh, "pdftotext -layout multipage.pdf - |" or die $!;
print "---------- Begin Page $pageNum ----------\n";
while ( my $line = <$fh> ) {
if ( $line =~ /\xC/ ) {
print "\n---------- End Page $pageNum ----------\n";
$pageNum++;
print "---------- Begin Page $pageNum ----------\n";
}
$i++;
print "\n<div class=\"line\"><div>$i</div>$line</div>";
}
close $fh;
Another option which may serve you is using CAM::PDF:
use strict;
use warnings;
use CAM::PDF;
my $pdf = CAM::PDF->new('multipage.pdf');
for my $pageNumber ( 1 .. $pdf->numPages() ) {
my $pageText = $pdf->getPageText($pageNumber);
my @certainLines = ( split /\n/, $pageText )[ 9 .. 14 ];
print "---------- Lines 10 - 15 on Page $pageNumber ----------\n";
print +( join "\n", @certainLines ) . "\n";
print "---------- End Page $pageNumber ----------\n";
}
The above shows how to grab a range of text lines from the converted pdf page. You may find, however, that pdftotext does a better rendering job.
Hope this helps!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|