Count the number of pages in a PDF in PHP, VB, VC

Question:I need a way to count the number of pages of a PDF in PHP. I've done a bit of Goggling and the only things I've found either utilize shell/bash scripts, perl, or other languages, but I need something in native PHP, VB .NET, MS Visual Basic, Borland Delphi, or others. Are there any libraries or examples of how to do this on VeryPDF?

Answer: According to your needs, maybe you can have a free trial of this software: VeryPDF Advanced PDF Tools SDK. By this SDK version,  you can count PDF page number in PHP, VB .NET, MS Visual Basic, Borland Delphi, or others. This software can help you edit PDF description, PDF custom description, PDF OpenAction options, PDF page view options, PDF metadata contents, and so on.  Please check more functions of this software on homepage, in the following part, let us check how to use this software.

Step 1. Free download Advanced PDF Tools SDK

  • There are two license types of this software: server version and developer license. By the server version, you can install this software under the whole sever. By the developer version, you can you can integrate the corresponding SOFTWARE into your developed software and redistribute it with royalty-free. If the SOFTWARE contains source codes, you have the right to modify and reuse the codes under the Developer License.
  • When downloading finishes, there will be a zip file. Please extract it to some folder then you can call it from PHP or others computer language according to your needs.

Step 2. Count PDF page number

  • For showing counting PDF page number effect, I will count PDF page number by command line from MS Dos Window to have a check. Page count result will be shown at the bottom of MS Dos Windows. Meanwhile, by this software, you can get all the basic information of added PDF like I showed in the following snapshot.

page count

Here I show one example of calling this software from VB, VC++.

VB Example 2:
Private Sub VBCOMTest_Click()
        Dim nRet As Long
        Dim strCmd As String
        strCmd = "pdftools.exe" & " -x ""0 0 612 792"" -j ""612 792 true"""
        strCmd = strCmd & " -$ XXXXXXXXXXXXXXX"
        strCmd = strCmd & " -i C:\test.pdf"
        strCmd = strCmd & " -o C:\_test.pdf"
        Set PDFToolsCOM = CreateObject("PDFTools.PDFToolsCOM")
        nRet = PDFToolsCOM.com_VeryPDF_PDFTools(strCmd)
        Set PDFToolsCOM = Nothing
        MsgBox (Str(nRet))
End Sub
VC++ Example:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <io.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <conio.h>
#include <ctype.h>
#include <windows.h>
__declspec(dllexport) int WINAPI VeryPDF_PDFTools(LPCTSTR lpCommand);
void main()
{
        char szCommandLine[1024];
        char *lpLicenseKey = "XXXXXXXXXXXXXX";
        sprintf(szCommandLine,"pdftools.exe \"-$\" \"%s\" -x \"0 0 612 792\" -j \"612 792 true\" -i \"%s\" -o \"%s\"",
        lpLicenseKey, "C:\\test.pdf", "C:\\_test.pdf");
        int nRet = VeryPDF_PDFTools(szCommandLine);
}

During the using, if you have any question, please contact us as soon as possible.

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)

Related Posts

This entry was posted in Advanced PDF Tools and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


Verify Code   If you cannot see the CheckCode image,please refresh the page again!