How to get the first two pages of a PDF document using C#?

   Sometime, we need to extract pages from PDF documents using C#. In this article, I will take getting first two pages of a PDF document for examples to show you how to extract pages from PDF. The software I use is named as VeryPDF PDF Split-Merge SDK, by which we can extract pages from PDF in any programming language like C++, Visual Basic, Delphi, ASP and others. Please check more related information on homepage, in the following part, let us check how to use this software.

Step 1. Free download PDF Split-Merge SDK

  • There are two versions of SDK: server version and developer version. By the server version, you can use this software under the whole server. By the developer version, you have the right to integrate the corresponding SOFTWARE into your developed software and redistribute it with royalty-free.
  • When downloading finishes, there will be a zip file. Please extract it to some folder then you can find the executable file and help documents.

Step 2. Get the first two pages of a PDF document using C#

  • When you use this software, please refer to the usage and example.
  • Here are some command line examples for your reference:
  • pdfpg.exe delete C:\A.pdf,3-n C:\out.pdf
    When you only need the first two pages, please delete pages from 3 to the end. N here stands for the last page. There are more examples for your reference. By the following code templates, you can delete any pages from PDF. By those command line, you can also apply them in C# code.
    pdfpg.exe delete C:\A.pdf,-20,50 C:\out.pdf
    pdfpg.exe delete C:\A.pdf,1,3- C:\out.pdf
    pdfpg.exe delete C:\A.pdf,1,2,3 C:\out.pdf
    pdfpg.exe delete C:\A.pdf,1,1-9 C:\out.pdf
    pdfpg.exe delete C:\A.pdf,even C:\out.pdf
    pdfpg.exe delete C:\A.pdf,odd C:\out.pdf

  • Here is code example of calling this software from C#, please have a check. //Extract pages from an existing PDF file

HPDF hPDF = PDF_Open(szInPDF);
bRet = PDF_ExtractPages(hPDF, szOutPDF1, "1-3");
bRet = PDF_ExtractPages(hPDF, szOutPDF2, "2-6")
bRet = PDF_ExtractPages(hPDF, szOutPDF3, "10");

This software also can be used to split PDF file into single page, merge many PDF files into one, split PDF and then merge PDF files. Here is one code examples for your reference.
//Extract and merge PDF files together

         GetModulePath(szOutMergedPDF, "merged2.pdf");
         sprintf(szMergePDFs, "%s*1,2,3,8-10", szInPDF);
         bRet = PDF_MergePDFFiles(szMergePDFs, szOutMergedPDF);

There are two many functions of this software, I can not list all of them here. If you need to know more parameters and code examples, please check them in the download package. During the using, if you have any question, please contact us as soon as possible.

VN:F [1.9.20_1166]
Rating: 9.0/10 (1 vote cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)
How to get the first two pages of a PDF document using C#?, 9.0 out of 10 based on 1 rating

Related 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!