Question: I need a way to count the number of pages of a PDF in PHP. I've done a bit of Googling and the only things I've found either utilize shell/bash scripts, perl, or other languages, but I need something in Visual C++. Are there any libraries or examples of how to do this? Is there a solution on VeryPDF?
Answer: According to your needs, maybe you can have a free trial of this software: VeryPDF PDFPrint SDK. This software is professionally for printing PDF file by command line. But by this software, you can also count PDF page number from native PHP code. And this SDK software also supports C#, VB .NET, MS Visual Basic, Borland Delphi, VBA (MS Office products such as Access) and C++ via COM, C and C++ via native C other programming languages. Please check more detail information of this software on homepage. In the following part, let us check how to count PDF page number by this software.
Step 1. Free download PDFPrint SDK
- Same with other command line version software, for uploading and downloading easily, we have compressed it to a zip file. When downloading finishes, there will be a zip file. Please extract it to some folder then you can check related elements.
- And if you choose the command line version, you can also call it from the native Visual C++. But by the SDK version, you can develop some software based on this software more easily.
Step 2. Count PDF page number in Visual C++.
- When you use this software, please refer to the usage and examples.
- For showing counting PDF page number effect more easily, let us check the effect from the MS Dos Windows.
The parameter you may use:
-getpagecount : read page count from input PDF file
pdfprint.exe -getpagecount C:\input.pdf
Checking from the above snapshot, we can get that this software will show the page number of the input PDF file by the easiest method. Once you see it then you can how many pages of the input PDF file.
- And when you need to call this software from Visual C++ to count PDF page number, please refer to the following code templates:
void main(int argc, char *argv)
if(argc != 2)
char *lpPDFName = argv;
char *lpRegcode = "XXXXXXXXXXXXXXXXXXXX";
sprintf(szCommandLine,"pdfprint -quiet -getpagecount \"%s\""
int nPageCount = VeryPDF_PDFPrint(szCommandLine);
printf("PageCount = %d\n", nPageCount);
sprintf(szCommandLine,"pdfprint \"-$\" \"%s\" -pdforient 4
-scalex -1 -scaley -1 \"%s\"", lpRegcode,lpPDFName);
int nRet = VeryPDF_PDFPrint(szCommandLine);
printf("Return Value = %d\n",nRet);
During the using, if you have any question, please contact us as soon as possible.