通过 C# 将页面添加到 PDF

使用适用于 .NET 库的 Aspose.PDF 以编程方式将页面插入到 PDF 文档

如何使用 C# 向 PDF 添加页面

為了在PDF檔中插入頁面,我們將使用[Aspose.PDF用於.NET](https://products.aspose.com/pdf/net)API,這是一個功能豐富,功能強大且易於使用的文檔操作API,適用於 net 平臺。打開 [NuGet](https://www.nuget.org/packages/aspose.pdf) 包管理器,搜索“.PDF”並安裝。您也可以從程式包管理器主控台使用以下命令。

Package Manager Console

PM > Install-Package Aspose.PDF

通過C#將頁面插入到 PDF 中


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

  1. 使用輸入的 PDF 檔案建立一個 Document 物件。

  2. 使用指定的索引呼叫 PageCollection 集合的 Insert 方法。

  3. 使用 Save 方法儲存輸出的 PDF。

將新頁面插入到 PDF 中

var inputFile = Path.Combine(dataDir, "InsertEmptyPage.pdf)");
var outputFile = Path.Combine(dataDir, "InsertEmptyPage_out.pdf)");
var pdfDocument = new Aspose.Pdf.Document(inputFile);
pdfDocument.Pages.Insert(2);
pdfDocument.Save(outputFile);