合并 PDF 文檔
Spire.PDF for .NET 是一款專門對(duì) Word 文檔進(jìn)行操作的 .NET 類庫。致力于在于幫助開發(fā)人員輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔,而無需安裝 Microsoft Word。
行號(hào)用于在每行文本旁邊顯示 Word 自動(dòng)計(jì)算的行數(shù)。當(dāng)我們需要參考合同或法律文件等文檔中的特定行時(shí),它非常有用。word中的行號(hào)功能允許我們?cè)O(shè)置起始值、編號(hào)間隔、與文本的距離以及行號(hào)的編號(hào)方式。使用 Spire.Doc,我們可以實(shí)現(xiàn)上述所有功能。本文將介紹如何將 HTML 轉(zhuǎn)換為 PDF。
歡迎加入spire技術(shù)交流群:767755948
合并 PDF 有許多必要的原因。例如,合并 PDF 文件可讓您打印單個(gè)文件,而無需為打印機(jī)排隊(duì)打印多個(gè)文件;通過減少需要搜索和整理的文件數(shù)量,合并相關(guān)文件可簡化管理和存儲(chǔ)多個(gè)文件的過程。在本文中,您將學(xué)習(xí)如何在 C# 和 VB.NET 中使用 Spire.PDF for .NET 將多個(gè) PDF 文檔合并為一個(gè) PDF 文檔,以及如何將不同 PDF 文檔中的選定頁面合并為一個(gè) PDF。- 將多個(gè) PDF 合并為一個(gè) PDF
- 將不同 PDF 中的選定頁面合并為一個(gè) PDF
首先,您需要將 Spire.PDF for.NET 軟件包中包含的 DLL 文件作為引用添加到您的 .NET 項(xiàng)目中。這些 DLL 文件既可以從這個(gè)鏈接下載,也可以通過 NuGet 安裝。
PM> Install-Package Spire.PDF將多個(gè) PDF 文件合并為一個(gè) PDF 文件
Spire.PDF for .NET提供了PdfDocument.MergeFiles()方法,用于將多個(gè)PDF文檔合并為一個(gè)文檔。具體步驟如下。
- 獲取要合并文檔的路徑并將其存儲(chǔ)在字符串?dāng)?shù)組中。
- 調(diào)用PdfDocument.MergeFiles()方法合并這些文件。
- 使用PdfDocumentBase.Save()方法將結(jié)果保存為PDF文檔。
【C#】
using System;
using Spire.Pdf;
namespace MergePDFs
{
    class Program
    {
        static void Main(string[] args)
        {
            //Get the paths of the documents to be merged
            String[] files = new String[] {
                "C:\\Users\\Administrator\\Desktop\\PDFs\\sample-1.pdf",
                "C:\\Users\\Administrator\\Desktop\\PDFs\\sample-2.pdf",
                "C:\\Users\\Administrator\\Desktop\\PDFs\\sample-3.pdf"};
            //Merge these documents and return an object of PdfDocumentBase
            PdfDocumentBase doc = PdfDocument.MergeFiles(files);
            //Save the result to a PDF file
            doc.Save("output.pdf", FileFormat.PDF);
        }
    }
}
【VB.NET】 
Imports System
Imports Spire.Pdf
 
Namespace MergePDFs
    Class Program
        Shared  Sub Main(ByVal args() As String)
            'Get the paths of the documents to be merged
            Dim files() As String =  New String() {"C:\\Users\\Administrator\\Desktop\\PDFs\\sample-1.pdf","C:\\Users\\Administrator\\Desktop\\PDFs\\sample-2.pdf","C:\\Users\\Administrator\\Desktop\\PDFs\\sample-3.pdf"}
 
            'Merge these documents and return an object of PdfDocumentBase
            Dim doc As PdfDocumentBase =  PdfDocument.MergeFiles(files) 
 
            'Save the result to a PDF file
            doc.Save("output.pdf", FileFormat.PDF)
        End Sub
    End Class
End Namespace
 
 
	將不同 PDF 中選定的頁面合并到一個(gè) PDF 中
 Spire.PDF for .NET提供了PdfDocument.InsertPage()方法和PdfDocument.InsertPageRange()方法,用于從一個(gè)PDF文檔導(dǎo)入頁面或頁面范圍到另一個(gè)PDF文檔。以下是將不同 PDF 文檔中選定的頁面合并到一個(gè)新的 PDF 文檔中的步驟。 
- 獲取源文檔的路徑并將其存儲(chǔ)在一個(gè)字符串?dāng)?shù)組中。
- 創(chuàng)建一個(gè)PdfDocument數(shù)組,并將每個(gè)源文檔加載到一個(gè)單獨(dú)的PdfDocument對(duì)象中。
- 創(chuàng)建另一個(gè) PdfDocument 對(duì)象,用于生成新文檔。
- 使用PdfDocument.InsertPage()方法和PdfDocument.InsertPageRange()方法將源文檔的選定頁面或頁面范圍插入到新文檔中。
- 使用PdfDocument.SaveToFile()方法將新文檔保存為PDF文件。
using System;
using Spire.Pdf;
namespace MergeSelectedPages
{
    class Program
    {
        static void Main(string[] args)
        {
            //Get the paths of the documents to be merged
            String[] files = new String[] {
                "C:\\Users\\Administrator\\Desktop\\PDFs\\sample-1.pdf",
                "C:\\Users\\Administrator\\Desktop\\PDFs\\sample-2.pdf",
                "C:\\Users\\Administrator\\Desktop\\PDFs\\sample-3.pdf"};
            //Create an array of PdfDocument
            PdfDocument[] docs = new PdfDocument[files.Length];
            //Loop through the documents
            for (int i = 0; i < files.Length; i++)
            {
                //Load a specific document
                docs[i] = new PdfDocument(files[i]);
            }
            //Create a PdfDocument object for generating a new PDF document
            PdfDocument doc = new PdfDocument();
            //Insert the selected pages from different documents to the new document
            doc.InsertPage(docs[0], 0);
            doc.InsertPageRange(docs[1], 1,3);
            doc.InsertPage(docs[2], 0);
            //Save the document to a PDF file
            doc.SaveToFile("output.pdf");
        }
    }
}
【VB.NET】 
Imports System
Imports Spire.Pdf
 
Namespace MergeSelectedPages
    Class Program
        Shared  Sub Main(ByVal args() As String)
            'Get the paths of the documents to be merged
            Dim files() As String =  New String() {"C:\\Users\\Administrator\\Desktop\\PDFs\\sample-1.pdf","C:\\Users\\Administrator\\Desktop\\PDFs\\sample-2.pdf","C:\\Users\\Administrator\\Desktop\\PDFs\\sample-3.pdf"}
 
            'Create an array of PdfDocument
            Dim docs() As PdfDocument =  New PdfDocument(files.Length) {} 
 
            'Loop through the documents
            Dim i As Integer
            For  i = 0 To  files.Length- 1  Step  i + 1
                'Load a specific document
                docs(i) = New PdfDocument(files(i))
            Next
 
            'Create a PdfDocument object for generating a new PDF document
            Dim doc As PdfDocument =  New PdfDocument() 
 
            'Insert the selected pages from different documents to the new document
            doc.InsertPage(docs(0), 0)
            doc.InsertPageRange(docs(1), 1,3)
            doc.InsertPage(docs(2), 0)
 
            'Save the document to a PDF file
            doc.SaveToFile("output.pdf")
        End Sub
    End Class
End Namespace
 
 
	申請(qǐng)臨時(shí)許可證
 若想從生成的文檔中刪除評(píng)估信息,或解除功能限制,申請(qǐng) 30 天試用許可證 

 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網(wǎng)安備
            50010702500608號(hào)
渝公網(wǎng)安備
            50010702500608號(hào)
             
            
 客服熱線
客服熱線