將頁面添加到帶有C#的 PDF 檔

C# 庫,用於使用我們的 API 將頁面添加到 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 檔案建立一個文件 物件。

  2. 使用指定的索引調用 頁面收集 集合的插入方法。

  3. 使用「保存」 方法保存輸出的 PDF。

將新頁面插入到 PDF 中


    // Open document
    Document pdfDocument1 = new Document(dataDir + "InsertEmptyPage.pdf");

    // Insert a empty page in a PDF
    pdfDocument1.Pages.Insert(2);
    dataDir = dataDir + "InsertEmptyPage_out.pdf";
    // Save output file
    pdfDocument1.Save(dataDir);