C #/VB. NET Merge PDF specified page

Source: Internet
Author: User

In the previous article, we already know how to merge, split multiple PDF files , in this article to merge, split the PDF document is mainly for the purpose of convenient document management to operate the document, in the document review, management and storage is very convenient and practical. But what if we want to merge the contents of some of the document pages in multiple documents? You can refer to the merge method that will be described next.

PS: This article is a further introduction to the merge feature of free spire.pdf , that is, how to merge the specified pages in multiple PDF documents (refer to the order page, specify multiple pages) as a new document, more about free spire.pdf the operation of the PDF document can be found here in the blog.

Using tools: Free spire.pdf for. NET

tip : After you download and install the component, notice that you add a reference Spire.PDF.dll file to the project program

Code details can be found in the following major code snippets:

           //Initializes an array of elements for the PDF document that needs to be merged            string[] files = {"sample1.pdf","sample2.pdf" }; pdfdocument[] Docs=NewPdfdocument[files.            Length]; //Traverse a PDF document             for(inti =0; I < files. Length; i++) {Docs[i]=Newpdfdocument (); Docs[i].            LoadFromFile (Files[i]); }            //Create a new PDF document and insert a specific page selected from the original documentPdfdocument doc =Newpdfdocument (); Doc. Insertpage (docs[0],0);//refer to the order pageDoc. Insertpagerange (docs[1],0,1);//Specify multiple pages//Save and name the merged document while running the documentDoc. SaveToFile ("Result.pdf"); Process.Start ("Result.pdf");

Before merging:

After merging:

All code

C#

usingspire.pdf;usingSystem.Diagnostics;namespacemergeselectedpdfpages{classProgram {Static voidMain (string[] args) {            string[] files = {"sample1.pdf","sample2.pdf" }; pdfdocument[] Docs=NewPdfdocument[files.            Length];  for(inti =0; I < files. Length; i++) {Docs[i]=Newpdfdocument (); Docs[i].            LoadFromFile (Files[i]); } pdfdocument Doc=Newpdfdocument (); Doc. Insertpage (docs[0],0); Doc. Insertpagerange (docs[1],0,1); Doc. SaveToFile ("Result.pdf"); Process.Start ("Result.pdf"); }    }}

vb.net

Imports spire.pdfimports system.diagnosticsnamespace mergeselectedpdfpages Class program Private Shared Sub Main (ByVal args () As String) Dim files () As String= New String () {"sample1.pdf","sample2.pdf"} Dim Docs () as Pdfdocument= New pdfdocument (files. Length)-1) {} Dim I as Integer=0Do While (i<files. Length) Docs (i)=New pdfdocument Docs (i). LoadFromFile (Files (i)) I= (i +1) Loop Dim Doc as Pdfdocument=New pdfdocument Doc. Insertpage (Docs (0),0) Doc. Insertpagerange (Docs (1),0,1) Doc. SaveToFile ("Result.pdf") Process.Start ("Result.pdf") End Sub end Classend Namespace

The above is the "How to merge PDF document designated page" of all the introduction, if you like, welcome reprint (Reproduced please specify the source)

Thanks for reading!

C #/VB. NET merge PDF specified page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.