翻譯|行業資訊|編輯:胡濤|2024-08-21 10:10:20.833|閱讀 123 次
概述:在本文中,您將學習如何使用Spire.PDF for .NET以編程方式創建 PDF 作品集。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
PDF 作品集是一組文件,其中可以包含文本文檔、電子表格、電子郵件、圖像、PowerPoint 演示文稿和繪圖。盡管 PDF 作品集將不同類型的文件組合成一個單元,但其中的每個文件都保留了其原始格式、分辨率和大小。在本文中,您將學習如何使用Spire.PDF for .NET以編程方式創建 PDF 作品集。
Spire.PDF for .NET 是一款獨立 PDF 控件,用于 .NET 程序中創建、編輯和操作 PDF 文檔。使用 Spire.PDF 類庫,開發人員可以新建一個 PDF 文檔或者對現有的 PDF 文檔進行處理,且無需安裝 Adobe Acrobat。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團隊研發,不依賴第三方軟件,不受其他國家的技術或法律法規限制,同時適配國產操作系統如中科方德、中標麒麟等,兼容國產文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
由于 PDF 文件包是文件的集合,Spire.PDF for .NET 允許您使用PdfDocument.Collection屬性輕松創建它。然后,您可以使用PdfCollection.AddFile()方法將文件添加到 PDF 文件包中。詳細步驟如下:
【C#】
using System; using Spire.Pdf; namespace CreatePDFPortfolio { class Program { static void Main(string[] args) { // Specify the files String[] files = new String[] { "input.pdf", "sample.docx", "report.xlsx", "Intro.pptx", "logo.png" }; //Create a PdfDocument instance using (PdfDocument pdf = new PdfDocument()) { //Create a PDF portfolio and add files to it for (int i = 0; i < files.Length; i++) { pdf.Collection.AddFile(files[i]); } //Save the result file pdf.SaveToFile("PortfolioWithFiles.pdf", FileFormat.PDF); pdf.Dispose(); } } } }
【VB.NET】
Imports Spire.Pdf Namespace CreatePDFPortfolio Class Program Private Shared Sub Main(ByVal args() As String) ' Specify the files Dim files() As String = New String() {"input.pdf", "sample.docx", "report.xlsx", "Intro.pptx", "logo.png"} 'Create a PdfDocument instance Dim pdf As PdfDocument = New PdfDocument 'Create a PDF portfolio and add files to it Dim i As Integer = 0 Do While (i < files.Length) pdf.Collection.AddFile(files(i)) i = (i + 1) Loop 'Save the result file pdf.SaveToFile("PortfolioWithFiles.pdf", FileFormat.PDF) pdf.Dispose() End Sub End Class End Namespace
創建 PDF 文件包后,Spire.PDF for .NET 還允許您在 PDF 文件包內創建文件夾以進一步管理文件。詳細步驟如下:
【C#】
using System; using Spire.Pdf; using Spire.Pdf.Collections; namespace CreatePDFPortfolio { class Program { static void Main(string[] args) { // Specify the files String[] files = new String[] { "input.pdf", "sample.docx", "report.xlsx", "Intro.pptx", "logo.png" }; //Create a PdfDocument instance using (PdfDocument pdf = new PdfDocument()) { //Create a PDF portfolio and add folders to it for (int i = 0; i < files.Length; i++) { PdfFolder folder = pdf.Collection.Folders.CreateSubfolder("Folder" + i); //Add files to the folders folder.AddFile(files[i]); } //Save the result file pdf.SaveToFile("PortfolioWithFolders.pdf", FileFormat.PDF); pdf.Dispose(); } } } }
【VB.NET
Imports Spire.Pdf Imports Spire.Pdf.Collections Namespace CreatePDFPortfolio Class Program Private Shared Sub Main(ByVal args() As String) ' Specify the files Dim files() As String = New String() {"input.pdf", "sample.docx", "report.xlsx", "Intro.pptx", "logo.png"} 'Create a PdfDocument instance Dim pdf As PdfDocument = New PdfDocument 'Create a PDF portfolio and add folders to it Dim i As Integer = 0 Do While (i < files.Length) Dim folder As PdfFolder = pdf.Collection.Folders.CreateSubfolder(("Folder" + i)) 'Add files to the folders folder.AddFile(files(i)) i = (i + 1) Loop 'Save the result file pdf.SaveToFile("PortfolioWithFolders.pdf", FileFormat.PDF) pdf.Dispose() End Sub End Class End Namespace
歡迎下載|體驗更多E-iceblue產品
獲取更多信息請咨詢 ;技術交流Q群(767755948)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn