没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|行业资讯|编辑:胡涛|2024-05-21 10:08:12.270|阅读 94 次
概述:在本文中,我将向您介绍如何使用 Spire.Office 将每种文件类型转换为 Adobe PDF,然后同时将它们合并为单个 PDF 文档。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
也许您在工作中遇到过这种情况:您收到很多不同文件类型的文件,有些是Word,有些是PowerPoint幻灯片,有些是Excel等,您需要将这些文件合并为一个PDF以供使用轻松分享。在本文中,我将向您介绍如何使用 Spire.Office 将每种文件类型转换为 Adobe PDF,然后同时将它们合并为单个 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下载 Spire.PDF for java下载
在此示例中,我首先准备了四种类型的文件(.doc、.docx、.xls、.pdf)。在 Spire.Office 中,它提供了SaveToStream()方法,允许我们将 Word 和 Excel 文档保存到流中,然后可以通过调用PdfDocument(Stream stream)方法将这些流转换为 PDF 文档。最后,我们可以使用PdfDocument.AppendPage()方法将这些 PDF 文件合并为一个文件。更多细节如下:
第 1 步:创建四个新的 PDF 文档。
PdfDocument[] documents = new PdfDocument[4];
步骤 2:加载 .doc 文件,将其保存到流中并从流中生成新的 PDF 文档。
using (MemoryStream ms1 = new MemoryStream()) { Document doc = new Document("01.doc", Spire.Doc.FileFormat.Doc); doc.SaveToStream(ms1, Spire.Doc.FileFormat.PDF); documents[0] = new PdfDocument(ms1); }
步骤3:重复步骤2,从.docx文件和.xls文件生成两个PDF文档。
using (MemoryStream ms2 = new MemoryStream()) { Document docx = new Document("02.docx", Spire.Doc.FileFormat.Docx2010); docx.SaveToStream(ms2, Spire.Doc.FileFormat.PDF); documents[1] = new PdfDocument(ms2); } using (MemoryStream ms3 = new MemoryStream()) { Workbook workbook = new Workbook(); workbook.LoadFromFile("03.xls", ExcelVersion.Version97to2003); workbook.SaveToStream(ms3, Spire.Xls.FileFormat.PDF); documents[2] = new PdfDocument(ms3); }
步骤 4:加载 .pdf 文件并将其保存到文档[3]。
documents[3] = new PdfDocument("04.pdf");
步骤5:将文档[0]、[1]、[2]附加到文档[3]并另存为新的PDF文档。
for (int i = 2; i > -1; i--) { documents[3].AppendPage(documents[i]); } documents[3].SaveToFile("Result.pdf");
效果截图:
完整代码:
[C#]
using Spire.Doc; using Spire.Xls; using Spire.Pdf; namespace MergeMultiTypestoOnePDF { class Program { static void Main(string[] args) { PdfDocument[] documents = new PdfDocument[4]; using (MemoryStream ms1 = new MemoryStream()) { Document doc = new Document("01.doc", Spire.Doc.FileFormat.Doc); doc.SaveToStream(ms1, Spire.Doc.FileFormat.PDF); documents[0] = new PdfDocument(ms1); } using (MemoryStream ms2 = new MemoryStream()) { Document docx = new Document("02.docx", Spire.Doc.FileFormat.Docx2010); docx.SaveToStream(ms2, Spire.Doc.FileFormat.PDF); documents[1] = new PdfDocument(ms2); } using (MemoryStream ms3 = new MemoryStream()) { Workbook workbook = new Workbook(); workbook.LoadFromFile("03.xls", ExcelVersion.Version97to2003); workbook.SaveToStream(ms3, Spire.Xls.FileFormat.PDF); documents[2] = new PdfDocument(ms3); } documents[3] = new PdfDocument("04.pdf"); for (int i = 2; i > -1; i--) { documents[3].AppendPage(documents[i]); } documents[3].SaveToFile("Result.pdf"); } } }
[VB.NET]
Imports Spire.Doc Imports Spire.Xls Imports Spire.Pdf Namespace MergeMultiTypestoOnePDF Class Program Private Shared Sub Main(args As String()) Dim documents As PdfDocument() = New PdfDocument(3) {} Using ms1 As New MemoryStream() Dim doc As New Document("01.doc", Spire.Doc.FileFormat.Doc) doc.SaveToStream(ms1, Spire.Doc.FileFormat.PDF) documents(0) = New PdfDocument(ms1) End Using Using ms2 As New MemoryStream() Dim docx As New Document("02.docx", Spire.Doc.FileFormat.Docx2010) docx.SaveToStream(ms2, Spire.Doc.FileFormat.PDF) documents(1) = New PdfDocument(ms2) End Using Using ms3 As New MemoryStream() Dim workbook As New Workbook() workbook.LoadFromFile("03.xls", ExcelVersion.Version97to2003) workbook.SaveToStream(ms3, Spire.Xls.FileFormat.PDF) documents(2) = New PdfDocument(ms3) End Using documents(3) = New PdfDocument("04.pdf") For i As Integer = 2 To -1 + 1 Step -1 documents(3).AppendPage(documents(i)) Next documents(3).SaveToFile("Result.pdf") End Sub End Class End Namespace
欢迎下载|体验更多E-iceblue产品
获取更多信息请咨询 ;技术交流Q群(767755948)
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@ke049m.cn
Tech Soft 3D 正式整合旗下 SDK 工具包,构建以数据、图形、仿真和建模为核心的 HOOPS 产品体系
在当今的数据驱动时代,Python 开发者经常需要将列表(一种基本的 Python 数据结构)转换为 Excel 电子表格。Excel 作为各行业通用的数据展示、报告生成与信息共享工具,无论是生成业务报告、准备分析数据,还是与非技术人员协作,掌握将 Python 列表导出为 Excel 的高效方法都至关重要。
本篇教程,我们将学习如何使用Aspose.CAD for Python via .NET将 SVG 转换为PNG 。这款 3D CAD SDK 有助于实现单个文件和多个文件格式转换的自动化。我们将编写一个完整的代码示例,以演示Aspose.CAD for Python via .NET的可用性和效率。
在制造业数字化项目中,让数据流动起来,往往比让设备动起来还难。
专业的.NET Office套件,涵盖office文档创建、编辑、转换、管理和OCR内容识别等操作
Spire.Doc for .NETSpire.Doc for .NET 是一款专门对 Word 文档进行操作的 .NET 类库。
Spire.XLS for .NETSpire.XLS for .NET是专业.NET Excel组件,快速完成对Excel各类编程操作
Spire.PDF for .NETSpire.PDF for .NET是独立的PDF控件,用于.NET程序中创建、编辑和操作PDF文档
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@ke049m.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢