want to determine information from a PDF file

I want to be able to determine the size of the print that will appear when a PDF file is printed.  I need to know the number of pages and the size of the pages.  I assume that there is a module that will do that but am just not seeing it in the CPAN

Please provide a trivial example.  I want to be able to determine the size of any output that will be generated for a given PDF file
LVL 8
jhurstAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dgssoftwareCommented:
I've used PDF::Creat and PDF::Image::JPEGImage previously, I also am aware PDF::Parse exists.

Should be just a case of:

---
use PDF::Parse;
my $pdf = PDF::Parse->new();

my $pages = $pdf->Pages;
---

the examples at CPAN seem quite straightforward.
jhurstAuthor Commented:
and where would I specify the file name here?
dgssoftwareCommented:
CPAN really is your friend: http://search.cpan.org/~antro/PDF-111/PDF/Parse.pm

but:

--
use PDF::Parse;
my $pdf = PDF::Parse->new();

my $filename = 'filename.pdf';

$pdf->TargetFile($filename); # set the file we want to interogate

my $pages = $pdf->Pages;
--
jhurstAuthor Commented:
I tried this and for some reason it does not work.  I know that the file is correct since I am able to actually print it and in fact I can even use imageMagick to look at it and make sure of all that I need
dgssoftwareCommented:
I said I'd not used this module in particular, just the other variants in that toolbox.

I just checked on PerlMonks to confirm what is current, seems CAM::PDF is preffered.

---
use CAM::PDF;
use Data::Dumper;

my $doc = CAM::PDF->new('filename.pdf'); # single A4 page

print $doc->numPages(); # printed 1

my $page_dimension = [ $doc->getPageDimensions(1) ]; # returns array of page points
print Dumper( \$page_dimension );

---

Content of $page_dimension

$VAR1 = \[
            '0',
            '0',
            '842',
            '595'
          ];

From the doc: http://search.cpan.org/~CDOLAN/CAM-PDF/lib/CAM/PDF.pm

$doc->getPageDimensions($pagenum)

    Returns an array of x, y, width and height numbers that define the dimensions of the specified page in points (1/72 inches). Technically, this is the MediaBox dimensions, which explains why it's possible for x and y to be non-zero, but that's a rare case.

    For example, given a simple 8.5 by 11 inch page, this method will return (0,0,612,792).

    This method will die() if the specified page number does not exist.

Hope that helps!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.