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