Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the number of pages in a PDF file in Perl?

Tags:

pdf

perl

pdflib

Is there any Perl script to read multiple PDF files and get the number of pages in it?

By using PDFlib or pdftet.

like image 853
Anil Avatar asked Dec 19 '08 04:12

Anil


People also ask

How do I count pages in PDF?

In Adobe Acrobat Pro, go to file > create PDF > merge files into a single PDF. Then add files and select the files you want. Click combine, and see how many pages are in the final PDF.

How many pages does a PDF have?

1 Correct answer In terms of the question of how many pages a single PDF file can contain, there is no set limit.

How do I count the number of pages in a PDF in PHP?

php function count_pdf_pages($pdfname) { $pdftext = file_get_contents($pdfname); $num = preg_match_all("/\/Page\W/", $pdftext, $dummy); return $num; } $pdfname = 'example. pdf'; // Put your PDF path $pages = count_pdf_pages($pdfname); echo $pages; ?>


1 Answers

How about just using Perl with the PDF::API2?

#!/usr/bin/perl

use PDF::API2;

foreach $doc (@ARGV)
{
    $pdf = PDF::API2->open($doc);
    $pages = $pdf->pages;
    $totalpages += $pages;

    print "$doc contains $pages pages\n";
}

print "Total pages of pdf pages = $totalpages\n";
like image 117
shank Avatar answered Sep 28 '22 16:09

shank