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 (referring to the order page, specifying multiple pages) as a new document
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:

//初始化数组,数组元素为需要合并的PDF文档string[] files = { "sample1.pdf", "sample2.pdf" };PdfDocument[] docs = new PdfDocument[files.Length];//遍历PDF文档for (int i = 0; i < files.Length; i++){docs[i] = new PdfDocument();docs[i].LoadFromFile(files[i]);}//创建一个新的PDF文档并插入从原文档选取的指定页PdfDocument doc = new PdfDocument();doc.InsertPage(docs[0], 0);//指定单页(文档1的第1页)doc.InsertPageRange(docs[1], 0, 1);//指定多页 (文档2的第1页和第2页)//保存并命名合并后的文档,同时运行文档doc.SaveToFile("Result.pdf");Process.Start("Result.pdf");

Before merging:

After merging:

All code
C#

using Spire.Pdf;using System.Diagnostics;namespace MergeSelectedPDFpages{    class Program    {        static void Main(string[] args)        {            string[] files = { "sample1.pdf", "sample2.pdf" };            PdfDocument[] docs = new PdfDocument[files.Length];            for (int i = 0; i < files.Length; i++)            {               docs[i] = new PdfDocument();               docs[i].LoadFromFile(files[i]);            }            PdfDocument doc = new PdfDocument();            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 = 0            Do 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

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.