Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Count the number of images in pdf

by anniyan (Monk)
on Dec 21, 2005 at 12:15 UTC ( #518293=perlquestion: print w/replies, xml ) Need Help??
anniyan has asked for the wisdom of the Perl Monks concerning the following question:

Monks i have a pdf file which contains many images. I want to count the number of images in the given pdf. Is it possible to do that through perl? Will PDF::API2 be useful? or Is there any other module to accomplish is this job?


Replies are listed 'Best First'.
Re: Count the number of images in pdf
by etm117 (Pilgrim) on Dec 21, 2005 at 12:38 UTC
    UPDATE:As marto points out, the OP's question was the number of images in a PDF file, not the number of pages. Thus the below is not the answer asked for.

    I have never used it, but quickly browsing the documentation you linked in your post I found that you can use the 'pages' function:

    $pagenumber = $pdf->pages
        Returns the number of pages in the document.

    For Example:

    use PDF::API2; my $pdf = PDF::API2->open('test_file.pdf'); print "'test_file.pdf' has " . $pdf->pages . " pages\n";
        Wow!, My bad... I hadn't had my first cup of coffee yet, and I must have read the word 'images' as 'pages'.

        Sorry for the confusion anniyan

        marto thanks thats wonderful. Just now i tested using and accomplished my job perfectly. Also thanks to etm117.

        (CREATED in HELL by DEVIL to s|EVILS|GOODS|g in WORLD)

Re: Count the number of images in pdf
by CountOrlok (Friar) on Dec 21, 2005 at 15:00 UTC
    I don't see how one can cycle through the objects in the PDF document in PDF::API2. From what I see, it gives you the ability to add objects but not browse through current objects.

    What would be useful in your case would be the ability to cylce through all objects in the document and if the "Type" of the object is "XObject" and "Subtype" is "Image", then you know you have come across an image.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://518293]
Approved by prasadbabu
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2016-09-25 23:03 GMT
Find Nodes?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:

    Results (473 votes). Check out past polls.