Solved

Command Line tool to call TIFF/PDF page counter?

Posted on 2010-11-23
8
901 Views
Last Modified: 2012-05-10
Hello experts,

I have a desire to count the pages of a PDF file from the command line.  Is anyone aware of a program that could do this?  Or a command that could potentially do this?

Thanks in advance?
0
Comment
Question by:robthomas09
  • 5
  • 2
8 Comments
 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
ID: 34199130
do you want to get how many pages (a numeric value) are there in a pdf file, or create an image? can you please elaborate more...
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 34200066
If you wait another month you can get a free tool that does this from:

http://counter.tiff-tools.com/

~bp
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 34200199
Here's a way to do it in VB Script if that is useful to you?

~bp

iPages = PageCount("C:\_temp\ctt2.pdf")
Wscript.Echo iPages
Wscript.Quit

Function PageCount(sFile)
    Set oPDF = CreateObject("AcroExch.PDDoc")
    If oPDF.Open(sFile) Then
        PageCount = oPDF.GetNumPages()
        Set oPDF = Nothing
    Else
        PageCount = -1
    End If
End Function

Open in new window

0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 54

Expert Comment

by:Bill Prew
ID: 34200261
You can also grab a copy of pdfinfo.exe at the following link, and parse the output from it in a FOR statement (let me know if you want help with that) to get the page count in a batch script.

ftp://ftp.foolabs.com/pub/xpdf/xpdf-3.02pl5-win32.zip

~bp
0
 

Author Comment

by:robthomas09
ID: 34200779
Thank you everyone for your replies.  We are actually running a program called Mirth, an hl7 interface engine, where we can use Javascript to execute a command line statement.  We are looking to count the pages of a particular PDF, and return a numeric value that represents how many pages it has.
Thanks!
0
 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 34201242
Okay, here's a simple approach.  First, save this code as a small VBS file, lets call it PDFPAGES.VBS.

Set oPDF = CreateObject("AcroExch.PDDoc")
If oPDF.Open(WScript.Arguments.Item(0)) Then
   Wscript.Echo oPDF.GetNumPages()
Else
   Wscript.Echo -1
End If

Open in new window

Then from your Javascript mode, run the following command line:

CSCRIPT //NOLOGO PDFPAGES.VBS "c:\temp\filename.pdf"

where the PDF file that you want to get the page count is last on the command line.  The VB script will run, and display to the console the number of pages.  You will need to trap that in the javascript and grab it (I'm not a javascript jock).

~bp
0
 

Author Closing Comment

by:robthomas09
ID: 34234258
Thanks for your hard work bp - golden.
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 34234422
Great, glad that was useful, thanks.

~bp
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ability to edit PDF documents can be useful, however it may not be a straight forward process. Many non-technical people don't realise that a PDF document is basically an image rather than a text file, even if it contains nothing but text. If…
Power PDF (http://www.nuance.com/for-business/document-imaging-and-scanning/power-pdf-converter/index.htm) is the newest product from the Document Imaging division of Nuance Communications (http://www.nuance.com/). It is available in two editions — …
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question