提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:李显亮|2020-08-11 10:26:50.430|阅读 746 次
概述:轻松可靠地将文档从一种格式转换为另一种格式的能力是Aspose.Words的一项关键功能。PDF是一种最受欢迎的转换格式,本文将讲解如何将Word文档和图像转换为PDF。
#慧都22周年庆大促·界面/图表报表/文档/IDE/IOT/测试等千款热门软控件火热促销中>>
相关链接:
Aspose.Words for Java是功能丰富的文字处理API,开发人员可以在自己的Java应用程序中嵌入生成,修改,转换,呈现和打印Microsoft Word支持的所有格式的功能。它不依赖于Microsoft Word,但是它提供了Microsoft Word通过其API支持的功能。
>>Aspose.Words for Java已经更新至v20.7,有97项改进和修复,点击下载体验
轻松可靠地将文档从一种格式转换为另一种格式的能力是Aspose.Words的一项关键功能。PDF是一种最受欢迎的转换格式,一种固定布局的格式,可以在各种平台上呈现文档时保留其原始外观。Aspose.Words中使用“渲染”一词来描述将文档转换为分页或具有页面概念的文件格式的过程。
从Word到PDF的转换是一个相当复杂的过程,需要几个计算阶段。Aspose.Words布局引擎模仿了Microsoft Word的页面布局引擎的工作方式,使PDF输出文档看起来与Microsoft Word中所看到的尽可能接近。使用Aspose.Words,您可以通过编程方式将文档从DOC或DOCX格式转换为PDF,而无需使用Microsoft Office。本文介绍了如何执行此转换。
请注意,文档中的页数会影响转换时间。
在Aspose.Words中从DOC或DOCX文档格式转换为PDF格式非常容易,只需两行代码即可完成:
下面的代码示例演示如何使用Save方法将文档从DOCX转换为PDF:
// Load the document from disk. Document doc = new Document(dataDir + "Template.doc"); // Save the document in PDF format. dataDir = dataDir + "output.pdf"; doc.save(dataDir);
请注意,使用相同的技术,可以将任何流程布局格式的文档转换为PDF格式。
Aspose.Words提供 PdfCompliace 枚举以支持将DOC或DOCX转换为各种PDF格式标准(例如PDF 1.7,PDF 1.5等)。下面的代码示例演示如何将文档转换为PDF使用1.7 PdfSaveOptions 与符合PDF17:
// The path to the documents directory. Document originalDoc = new Document(dataDir + "Document.docx"); // Provide PDFSaveOption compliance to PDF17 // or just convert without SaveOptions PdfSaveOptions pso = new PdfSaveOptions(); pso.setCompliance(PdfCompliance.PDF_17); originalDoc.save(dataDir + "Output.pdf", pso);
转换为PDF不受Microsoft Word文档格式的限制。Aspose.Words支持的任何格式,包括以编程方式创建的格式,都可以转换为PDF。例如,我们可以将单页图像(例如JPEG,PNG,BMP,EMF或WMF)以及多页图像(例如TIFF和GIF)转换为PDF。
下面的代码示例演示如何将JPEG和TIFF图像转换为PDF:
//将指定格式的图像转换为PDF。 ConvertImageToPDF(dataDir + “ Test.jpg ”,dataDir + “ TestJpg_out.pdf ”); ConvertImageToPDF(dataDir + “ Test.tiff ”,dataDir + “ TestTif_out.pdf ”);
| /** | |
|
|
* Converts an image to PDF using Aspose.Words for Java. |
|
|
* |
|
|
* @param inputFileName File name of input image file. |
|
|
* @param outputFileName Output PDF file name. |
|
|
* @throws Exception |
|
|
*/ |
|
|
public static void ConvertImageToPDF(String inputFileName, String outputFileName) throws Exception { |
|
|
// Create Aspose.Words.Document and DocumentBuilder. |
|
|
// The builder makes it simple to add content to the document. |
|
|
Document doc = new Document(); |
|
|
DocumentBuilder builder = new DocumentBuilder(doc); |
|
|
|
|
|
// Load images from the disk using the appropriate reader. |
|
|
// The file formats that can be loaded depends on the image readers available on the machine. |
|
|
ImageInputStream iis = ImageIO.createImageInputStream(new File(inputFileName)); |
|
|
ImageReader reader = ImageIO.getImageReaders(iis).next(); |
|
|
reader.setInput(iis, false); |
|
|
|
|
|
// Get the number of frames in the image. |
|
|
int framesCount = reader.getNumImages(true); |
|
|
|
|
|
// Loop through all frames. |
|
|
for (int frameIdx = 0; frameIdx < framesCount; frameIdx++) { |
|
|
// Insert a section break before each new page, in case of a multi-frame image. |
|
|
if (frameIdx != 0) |
|
|
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE); |
|
|
|
|
|
// Select active frame. |
|
|
BufferedImage image = reader.read(frameIdx); |
|
|
|
|
|
// We want the size of the page to be the same as the size of the image. |
|
|
// Convert pixels to points to size the page to the actual image size. |
|
|
PageSetup ps = builder.getPageSetup(); |
|
|
ps.setPageWidth(ConvertUtil.pixelToPoint(image.getWidth())); |
|
|
ps.setPageHeight(ConvertUtil.pixelToPoint(image.getHeight())); |
|
|
|
|
|
// Insert the image into the document and position it at the top left corner of the page. |
|
|
builder.insertImage( |
|
|
image, |
|
|
RelativeHorizontalPosition.PAGE, |
|
|
0, |
|
|
RelativeVerticalPosition.PAGE, |
|
|
0, |
|
|
ps.getPageWidth(), |
|
|
ps.getPageHeight(), |
|
|
WrapType.NONE); |
|
|
} |
|
|
|
|
|
if (iis != null) { |
|
|
iis.close(); |
|
|
reader.dispose(); |
|
|
} |
|
|
|
|
|
doc.save(outputFileName); |
|
|
} |
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@hmdbvip.cn




在嵌入式软件测试领域,对交叉编译代码进行单元测试是一大挑战。Parasoft C/C++test作为专业的C/C++测试工具,能够与劳特巴赫Trace32调试器深度集成。下面会详细介绍如何在C++test中配置Trace32调试器,实现对PowerPC架构程序的单元测试,涵盖环境设置、项目导入到测试执行的全过程。
本文将为大家介绍如何使用DevExpress WinForms数据网格控件实现摘要文本的格式化,欢迎下载最新版组件体验!
Parasoft C/C++test作为一款功能强大的自动化测试工具,为嵌入式开发提供了全面的测试解决方案。特别是在CCS开发环境中,C++test能够无缝集成,为F2812等DSP项目提供专业的单元测试支持。下面将介绍如何在CCS3环境下配置和使用C++test进行F2812项目的单元测试。
在嵌入式开发中,尤其是基于ARM架构的安全关键领域,单元测试是验证代码在目标硬件上运行时行为正确性的关键环节,对于保障最终产品的可靠性至关重要。下面将介绍如何利用Parasoft C/C++test开展单元测试,包括配置、执行及解决可能遇到的许可证问题,完成从静态检查到动态运行的完整测试闭环。
相关产品
可用于基于Java SE或EE的桌面,Web或任何种类应用程序的Native Java API。
最新文章 MORE
永利最大(官方)网站相关的文章 MORE
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@hmdbvip.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
永利最大(官方)网站