ToB企服应用市场:ToB评测及商务社交产业平台

标题: Spire.PDF for .NET【文档操作】演示:创建 PDF 组合 [打印本页]

作者: 络腮胡菲菲    时间: 2024-8-26 08:34
标题: Spire.PDF for .NET【文档操作】演示:创建 PDF 组合
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 等格式
Spire.PDF for.net下载   
创建 PDF 包并向其中添加文件

由于 PDF 文件包是文件的聚集,Spire.PDF for .NET 答应您使用PdfDocument.Collection属性轻松创建它。然后,您可以使用PdfCollection.AddFile()方法将文件添加到 PDF 文件包中。具体步骤如下:

【C#】
  1. using System;
  2. using Spire.Pdf;
  3. namespace CreatePDFPortfolio
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. // Specify the files
  10. String[] files = new String[] { "input.pdf", "sample.docx", "report.xlsx", "Intro.pptx", "logo.png" };
  11. //Create a PdfDocument instance
  12. using (PdfDocument pdf = new PdfDocument())
  13. {
  14. //Create a PDF portfolio and add files to it
  15. for (int i = 0; i < files.Length; i++)
  16. {
  17. pdf.Collection.AddFile(files[i]);
  18. }
  19. //Save the result file
  20. pdf.SaveToFile("PortfolioWithFiles.pdf", FileFormat.PDF);
  21. pdf.Dispose();
  22. }
  23. }
  24. }
  25. }
复制代码
【VB.NET】
  1. Imports Spire.Pdf
  2. Namespace CreatePDFPortfolio
  3. Class Program
  4. Private Shared Sub Main(ByVal args() As String)
  5. ' Specify the files
  6. Dim files() As String = New String() {"input.pdf", "sample.docx", "report.xlsx", "Intro.pptx", "logo.png"}
  7. 'Create a PdfDocument instance
  8. Dim pdf As PdfDocument = New PdfDocument
  9. 'Create a PDF portfolio and add files to it
  10. Dim i As Integer = 0
  11. Do While (i < files.Length)
  12. pdf.Collection.AddFile(files(i))
  13. i = (i + 1)
  14. Loop
  15. 'Save the result file
  16. pdf.SaveToFile("PortfolioWithFiles.pdf", FileFormat.PDF)
  17. pdf.Dispose()
  18. End Sub
  19. End Class
  20. End Namespace
复制代码


创建 PDF 包并向其中添加文件夹

创建 PDF 文件包后,Spire.PDF for .NET 还答应您在 PDF 文件包内创建文件夹以进一步管理文件。具体步骤如下:

【C#】
  1. using System;
  2. using Spire.Pdf;
  3. using Spire.Pdf.Collections;
  4. namespace CreatePDFPortfolio
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. // Specify the files
  11. String[] files = new String[] { "input.pdf", "sample.docx", "report.xlsx", "Intro.pptx", "logo.png" };
  12. //Create a PdfDocument instance
  13. using (PdfDocument pdf = new PdfDocument())
  14. {
  15. //Create a PDF portfolio and add folders to it
  16. for (int i = 0; i < files.Length; i++)
  17. {
  18. PdfFolder folder = pdf.Collection.Folders.CreateSubfolder("Folder" + i);
  19. //Add files to the folders
  20. folder.AddFile(files[i]);
  21. }
  22. //Save the result file
  23. pdf.SaveToFile("PortfolioWithFolders.pdf", FileFormat.PDF);
  24. pdf.Dispose();
  25. }
  26. }
  27. }
  28. }
复制代码
【VB.NET
  1. Imports Spire.Pdf
  2. Imports Spire.Pdf.Collections
  3. Namespace CreatePDFPortfolio
  4. Class Program
  5. Private Shared Sub Main(ByVal args() As String)
  6. ' Specify the files
  7. Dim files() As String = New String() {"input.pdf", "sample.docx", "report.xlsx", "Intro.pptx", "logo.png"}
  8. 'Create a PdfDocument instance
  9. Dim pdf As PdfDocument = New PdfDocument
  10. 'Create a PDF portfolio and add folders to it
  11. Dim i As Integer = 0
  12. Do While (i < files.Length)
  13. Dim folder As PdfFolder = pdf.Collection.Folders.CreateSubfolder(("Folder" + i))
  14. 'Add files to the folders
  15. folder.AddFile(files(i))
  16. i = (i + 1)
  17. Loop
  18. 'Save the result file
  19. pdf.SaveToFile("PortfolioWithFolders.pdf", FileFormat.PDF)
  20. pdf.Dispose()
  21. End Sub
  22. End Class
  23. End Namespace
复制代码



免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4