PDF 檔案合併 C#

在瀏覽器中合併 PDF 文件,而無需 Adobe 雜技演員或自動化 - C#。

如何使用 .NET 庫合併 PDF 檔

为了合并 PDF 文件,我们将使用 Aspose.PDF for .NET API,这是一款适用于 net 平台的功能丰富、功能强大且易于使用的文档操作 API。我们的.NET 库可以将文档从任何支持的下载格式转换为任何支持的保存格式。Aspose.PDF for .NET 库提供了相当通用的解决方案,可以帮助你解决转换文档的任务。Aspose.PDF 支持最多的常用文档格式,用于加载和保存。请您注意,当前部分仅描述了热门转化次数。当前页面提供有关将格式转换为格式的信息。但是,有许多组合可以转换文件。有关支持格式的完整列表,请参阅 [支持的文件格式] 部分 (https://docs.aspose.com/pdf/net/supported-file-formats/)。打开 NuGet 包管理器,搜索 aspose.pdf 并安装。您也可以使用软件包管理器控制台中的以下命令。

Package Manager Console

PM > Install-Package Aspose.PDF

通過C#合併 PDF 檔


您需要使用 [Aspose.PDF for .NET](https://releases.aspose.com/pdf/net) 來嘗試環境中的代碼。

  1. 開啟第一個文件。
  2. 開啟第二個文件。
  3. 將第二個文件的頁面添加到第一個文件。
  4. 儲存串聯的輸出檔

C# - 用於合併 PDF 檔的範例代碼。


    // Open first document
    Document pdfDocument1 = new Document(_dataDir + "Concat1.pdf");
    // Open second document
    Document pdfDocument2 = new Document(_dataDir + "Concat2.pdf");

    // Add pages of second document to the first
    document1.Pages.Add(document2.Pages);
    
    dataDir = dataDir + "ConcatenatePdfFiles_out.pdf";
    // Save concatenated output file
    pdfDocument1.Save(dataDir);