当前位置: 首页 > news >正文

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 文件包中。详细步骤如下:

  • 指定需要添加到 PDF 包的文件。
  • 创建PdfDocument实例。
  • 创建一个 PDF 文件包并使用PdfDocument.Collection.AddFile()方法向其中添加文件。
  • 使用PdfDocument.SaveToFile()方法保存结果文件。

【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.PdfNamespace 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

C#/VB.NET:创建 PDF 组合

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

创建 PDF 文件包后,Spire.PDF for .NET 还允许您在 PDF 文件包内创建文件夹以进一步管理文件。详细步骤如下:

  • 指定需要添加到 PDF 包的文件。
  • 创建PdfDocument实例。
  • 使用PdfDocument.Collection属性创建 PDF 组合。
  • 使用PdfCollection.Folders.CreateSubfolder()方法将文件夹添加到 PDF 包,然后使用PdfFolder.AddFile()方法将文件添加到文件夹中。
  • 使用PdfDocument.SaveToFile()方法保存结果文件。

【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.CollectionsNamespace 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

C#/VB.NET:创建 PDF 组合


http://www.mrgr.cn/news/8877.html

相关文章:

  • SpringMVC核心机制环境搭建
  • 编织网络之魂:Ruby网络编程指南
  • rt-studio+clion+cubemx联合使用(使用scons进行整合)
  • Python高光谱遥感数据处理与机器学习深度应用
  • 华为OD题目 csv格式的数据 字符串 用C没写出来
  • 分布式数据一致性小结
  • 2002-2023年中债国债3年期到期收益率
  • Golang测试func TestXX(t *testing.T)的使用
  • 【机器学习】 1. 总览介绍
  • openai whisper使用
  • 在VBA中调用Adobe Acrobat或Reader的命令行工具,实现PDF自动打印 (‾◡◝)
  • Spring Boot日志
  • 排序算法【希尔排序】
  • Activity的启动流程(AndroidU)
  • 【互动直播】支付能力视角与年龄的调节作用—推文分享—2024-08-25
  • 手把手教你搭建 Go 项目
  • 考研资讯平台
  • 【数据结构-前缀异或和】1442. 形成两个异或相等数组的三元组数目
  • 华为Cloud连接配置
  • 圈子论坛小程序搭建教程,系统快速部署上线指南,支持文章、源码、链接等上传