Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Command Line tool to call TIFF/PDF page counter?

Posted on 2010-11-23
8
899 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:HainKurt
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 53

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 53

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 53

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 53

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 53

Expert Comment

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

~bp
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe A recent question here at Experts Exchange piqued my interest, so I decided to provide a thorough solution and publ…
This article is in response to a question here (http://www.experts-exchange.com/Other/URLs/Q_28283850.html) at Experts Exchange. The Original Poster has a scanned signature and wants to make the background transparent so that the signature may be pl…
In this first video of the three-part Xpdf series, we introduce and describe Xpdf, a library containing nine command line utilities that perform various functions on PDF files. We show where the library is located and how to download it, discuss its…
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…

860 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