How can I get the number of color pages in a PDF file using C#?

Question:Given a PDF file with color and black & white pages, is there any way with C# to find out among the given pages which are color and which are black & white? Is there a solution on VeryDOC?

Answer:According to your needs, maybe you can have a free trial of software VeryDOC Spool File Page Counter SDK, by which you can count the black and white pages and color pages in document formats like PDF, PS and PCL files and it is useful for printer accounting software. Meanwhile this is SDK version software, it can be called from C# easily. It also can be called together with other programming language like Visual Basic, C/C++, Delphi, ASP, PHP, C#, .NET, etc. Please check more information of this software on homepage, in the following part, let us check how to use this software.

Step 1. Free download Spool File Page Counter SDK v2.0

  • When downloading finishes, there will be a zip file. Please extract it to some folder then you can use it normally like other SDK software.
  • And now there is no single user version of this software. If you need to develop it under single computer, please choose the server version, it also can be used under single computer.

Step 2. Count color page number of PDF.

  • When you need to call this software from C# for counting color page number, please refer to the following code template:
  • Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim bIsRenderToPDF As Integer
      Dim bwPageCount As Integer
      Dim colorPageCount As Integer
      Dim copyCount As Integer
      Dim nPageWidth As Double
      Dim nPageHeight As Double
      Dim strPaperSizeName As String
      Dim nRet As Integer
      Dim strMsg As String
      Dim strFileName As String

      bIsRenderToPDF = 0
      bwPageCount = 0
      colorPageCount = 0
      copyCount = 0
      nPageWidth = 0
      nPageHeight = 0
      strPaperSizeName = Space$(300)
      strFileName = Application.StartupPath() & "\test_tiger.pdf"
      nRet = ReadInfoFromPSFile(strFileName, bIsRenderToPDF, bwPageCount,
      colorPageCount, copyCount, nPageWidth, nPageHeight, strPaperSizeName)

      strMsg = strMsg + "FileName = " + strFileName + vbCrLf
      strMsg = strMsg + "bIsRenderToPDF = " + CStr(bIsRenderToPDF) + vbCrLf
      strMsg = strMsg + "bwPageCount = " + CStr(bwPageCount) + vbCrLf
      strMsg = strMsg + "colorPageCount = " + CStr(colorPageCount) + vbCrLf
      strMsg = strMsg + "copyCount = " + CStr(copyCount) + vbCrLf
      strMsg = strMsg + "PaperSizeName = " + CStr(strPaperSizeName) + vbCrLf
      MsgBox(strMsg)

      strMsg = strMsg + "FileName = " + strFileName + vbCrLf
      strMsg = strMsg + "bIsRenderToPDF = " + CStr(bIsRenderToPDF) + vbCrLf
      strMsg = strMsg + "bwPageCount = " + CStr(bwPageCount) + vbCrLf
      strMsg = strMsg + "colorPageCount = " + CStr(colorPageCount) + vbCrLf
      strMsg = strMsg + "copyCount = " + CStr(copyCount) + vbCrLf
      strMsg = strMsg + "PageWidth = " + CStr(nPageWidth) + vbCrLf
      strMsg = strMsg + "PageHeight = " + CStr(nPageHeight) + vbCrLf
      strMsg = strMsg + "PaperSizeName = " + CStr(strPaperSizeName) + vbCrLf
      MsgBox(strMsg)
    End Sub

    If you need to know more examples, please go to website. During the using, if you have any question, please contact us as soon as possible.

     

VN:F [1.9.20_1166]
Rating: 8.0/10 (1 vote cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)
How can I get the number of color pages in a PDF file using C#?, 8.0 out of 10 based on 1 rating

Random Posts

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!