翻譯|行業資訊|編輯:胡濤|2024-11-06 11:03:25.490|閱讀 95 次
概述:本文將向您展示如何在 C# 中在 PDF 文件中插入空白頁。通過使用 Spire.PDF,我們可以將空白頁添加到 PDF 文件中您想要的任何位置,例如 PDF 文件的開頭、中間或末尾。這非常簡單,您只需要三行代碼即可完成此任務。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Spire.PDF 具有在 C# 中添加、刪除空白頁的功能。我們已經向您展示了如何刪除 PDF 文件中的空白頁。本文將向您展示如何在 C# 中在 PDF 文件中插入空白頁。通過使用 Spire.PDF,我們可以將空白頁添加到 PDF 文件中您想要的任何位置,例如 PDF 文件的開頭、中間或末尾。這非常簡單,您只需要三行代碼即可完成此任務。
Spire.PDF for .NET 是一款獨立 PDF 控件,用于 .NET 程序中創建、編輯和操作 PDF 文檔。使用 Spire.PDF 類庫,開發人員可以新建一個 PDF 文檔或者對現有的 PDF 文檔進行處理,且無需安裝 Adobe Acrobat。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團隊研發,不依賴第三方軟件,不受其他國家的技術或法律法規限制,同時適配國產操作系統如中科方德、中標麒麟等,兼容國產文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
確保.NET 的 Spire.PDF已正確安裝,然后通過以下路徑在下載的 Bin 文件夾中添加 Spire.Pdf.dll 作為引用:“..\Spire.Pdf\Bin\NET4.0\Spire.Pdf.dll”。
以下代碼片段向您展示如何在 PDF 文件中插入空白頁。我們將向您展示如何將空白頁添加到文件末尾并將其作為文件的第二頁。
//create a PDF document and load file PdfDocument doc = new PdfDocument(); doc.LoadFromFile("sample.pdf"); //insert blank page at the end of the PDF file doc.Pages.Add(); //insert blank page as the second page doc.Pages.Insert(1); //Save the document to file doc.SaveToFile("result.pdf");
查看有效截圖如下:
在 PDF 文件末尾添加空白頁:
將空白頁添加為 PDF 文件的第二頁:
完整代碼:
using Spire.Pdf; using System; namespace InsertPage { class Program { static void Main(string[] args) { //create PdfDocument instance and load file PdfDocument doc = new PdfDocument(); doc.LoadFromFile("sample.pdf"); //insert blank page as last page doc.Pages.Add(); doc.SaveToFile("result.pdf"); doc.Close(); System.Diagnostics.Process.Start("result.pdf"); //create PdfDocument instance and load file PdfDocument doc2 = new PdfDocument(); doc2.LoadFromFile("sample.pdf"); //insert blank page as second page doc2.Pages.Insert(1); doc2.SaveToFile("result2.pdf"); doc2.Close(); System.Diagnostics.Process.Start("result2.pdf"); } } }
歡迎下載|體驗更多E-iceblue產品
獲取更多信息請咨詢 ;技術交流Q群(767755948)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn