翻译|使用教程|编辑:胡涛|2023-03-20 10:28:57.713|阅读 49 次
概述:在本文中,我将向您展示如何在C++应用程序中将Word DOC/DOCX 转换为 PDF。
# 31款JAVA开发必备控件和工具 # 界面/文档管理/报表/IDE等4000款产品火热销售中 >>
相关链接:
Aspose.Words 是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。此外,
Aspose API支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。
再次欢迎来到文件格式 API 主页!最近,我写了几篇博文来介绍在.NET(使用 C#)和Java应用程序中以编程方式将 Word (DOC/DOCX) 转换为 PDF 的各种场景。由于这是一个流行和广泛使用的特性,我想也为 C++ 涵盖它。因此,在本文中,我将向您展示如何在C++应用程序中将Word DOC/DOCX 转换为 PDF。本文介绍了以下 Word 到 PDF 的转换:
Aspose.Words for C++是一个高级库,无需 MS Word 即可在 C++ 应用程序中创建和操作 Word 文档格式。您可以通过NuGet安装它,也可以下载包含库文件以及准备运行源代码示例的完整包。
使用 Aspose.Words for C++ 将 Word 文档转换为 PDF 非常简单。以下是将 DOC/DOCX 文件转换为 PDF 的步骤。
以下代码示例显示了如何在 C++ 中将 DOCX 转换为 PDF。
// Load the document from disk. System::SharedPtr<Document> doc = System::MakeObject<Document>( u"Word.docx"); // Set the output PDF path System::String outputPath = u"DOCX-to-PDF.pdf"; // Convert DOCX to PDF doc->Save(outputPath); std::cout << "Converted DOCX to PDF successfuly.";
输入Word文档
转换后的 PDF 文档
PDF 格式支持各种 PDF 标准,包括 PDF/A、PDF/E 等。当您需要将 Word 文件转换为特定标准(如 PDF/A-1a)时,可能会有这种情况。在这种情况下,Aspose.Words for C++ 允许您为转换后的 PDF 设置所需的 PDF 标准。以下是在Word转PDF中设置PDF标准的步骤:
以下代码示例显示了如何将 Word DOCX 转换为符合 PDF/A-1a 标准的 PDF。
// Load the document from disk. System::SharedPtr<Document> doc = System::MakeObject<Document>( u"Word.docx"); // Set the output PDF path System::String outputPath = u"DOCX-to-PDFA.pdf"; // Set PDF options System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>(); options->set_Compliance(PdfCompliance::PdfA1a); // Save the document in PDF format. doc->Save(outputPath, options); std::cout << "Converted DOCX to PDF/A successfuly.";
您也可以只转换选定的页面,而不是将整个 Word 转换为 PDF。以下是仅将所需的 Word 页面转换为 PDF 的步骤:
以下代码示例显示了如何在 C++ 中将选定的 DOCX 页面转换为 PDF。
// Load the document from disk. System::SharedPtr<Document> doc = System::MakeObject<Document>( u"Word.docx"); // Set the output PDF path System::String outputPath = u"DOCX-to-PDF.pdf"; // Set PDF options System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>(); options->set_PageIndex(1); options->set_PageCount(2); // Save the document in PDF format. doc->Save(outputPath, options);
您还可以压缩生成的 PDF 文档以减小其大小。Aspose.Words for C++ 允许您分别使用PdfSaveOptions->set_TextCompression()和PdfSaveOptions->set_ImageCompression()方法应用文本和图像压缩。以下代码示例显示了在 C++ 中将 DOCX 转换为 PDF 时如何应用压缩。
// Load the document from disk. System::SharedPtr<Document> doc = System::MakeObject<Document>( u"Word.docx"); // Set the output PDF path System::String outputPath = u"DOCX-to-PDF.pdf"; // Set PDF options System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>(); // Set JPEG quality options->set_JpegQuality(100); // Save the document in PDF format doc->Save(outputPath, options);
以上便是在 ASP.NET MVC 中创建 MS Word 编辑器 ,要是您还有其他关于产品方面的问题,欢迎咨询我们,或者加入我们官方技术交流群。
欢迎下载|体验更多Aspose产品
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com
在对装配体进行装配时,如何使用用SOLIDWORKS创建智能零部件,然后在插入到装配体中?一个模型示例告诉你。
本文将为大家介绍基于DevExpress的GridControl实现的一些界面处理功能,欢迎下载最新版组件体验!
本指南将向您展示如何通过 Spire.Doc for .NET 创建条码的方法。
专业的电子表格控件,无需MS Excel也可满足一切Excel表格功能。
Aspose.Words for .NET无需Microsoft Word也可在任何平台上满足Word文档的一切操作需求。
Aspose.PDF for .NETPDF文档创建组件,无需Adobe Acrobat,也可以在任何平台上操作PDF文档。
服务电话
重庆/ 023-68661681
华东/ 18183052121
华南/ 18100878085
华北/ 17382392642
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@evget.com
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
慧都科技有限公司 版权所有 Copyright 2003-2023 渝ICP备12000582号-13 渝公网安备
50010702500608号