翻譯|行業(yè)資訊|編輯:胡濤|2024-11-06 11:03:25.490|閱讀 95 次
概述:本文將向您展示如何在 C# 中在 PDF 文件中插入空白頁(yè)。通過使用 Spire.PDF,我們可以將空白頁(yè)添加到 PDF 文件中您想要的任何位置,例如 PDF 文件的開頭、中間或末尾。這非常簡(jiǎn)單,您只需要三行代碼即可完成此任務(wù)。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Spire.PDF 具有在 C# 中添加、刪除空白頁(yè)的功能。我們已經(jīng)向您展示了如何刪除 PDF 文件中的空白頁(yè)。本文將向您展示如何在 C# 中在 PDF 文件中插入空白頁(yè)。通過使用 Spire.PDF,我們可以將空白頁(yè)添加到 PDF 文件中您想要的任何位置,例如 PDF 文件的開頭、中間或末尾。這非常簡(jiǎn)單,您只需要三行代碼即可完成此任務(wù)。
Spire.PDF for .NET 是一款獨(dú)立 PDF 控件,用于 .NET 程序中創(chuàng)建、編輯和操作 PDF 文檔。使用 Spire.PDF 類庫(kù),開發(fā)人員可以新建一個(gè) PDF 文檔或者對(duì)現(xiàn)有的 PDF 文檔進(jìn)行處理,且無需安裝 Adobe Acrobat。
E-iceblue 功能類庫(kù)Spire 系列文檔處理組件均由中國(guó)本土團(tuán)隊(duì)研發(fā),不依賴第三方軟件,不受其他國(guó)家的技術(shù)或法律法規(guī)限制,同時(shí)適配國(guó)產(chǎn)操作系統(tǒng)如中科方德、中標(biāo)麒麟等,兼容國(guó)產(chǎn)文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
確保.NET 的 Spire.PDF已正確安裝,然后通過以下路徑在下載的 Bin 文件夾中添加 Spire.Pdf.dll 作為引用:“..\Spire.Pdf\Bin\NET4.0\Spire.Pdf.dll”。
以下代碼片段向您展示如何在 PDF 文件中插入空白頁(yè)。我們將向您展示如何將空白頁(yè)添加到文件末尾并將其作為文件的第二頁(yè)。
//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 文件末尾添加空白頁(yè):
將空白頁(yè)添加為 PDF 文件的第二頁(yè):
完整代碼:
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"); } } }
歡迎下載|體驗(yàn)更多E-iceblue產(chǎn)品
獲取更多信息請(qǐng)咨詢 ;技術(shù)交流Q群(767755948)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn