在共享文档以前,一般使用Word到PDF的转换。可使用各类在线Word到PDF转换器,能够转换单个或有限数量的Word文档。可是,随着新兴的MS Word自动化和报告生成解决方案,Word到PDF的自动转换已成为系统的重要组成部分。同时,须要自动完成DOC / DOCX到PDF的批量转换,以减小时间和精力。编程
以前小编展现了如何使用Aspose.Words自动以Java/.NET编程方式将Word(DOC/DOCX)文档转换为PDF的过程。因为这是一个流行且普遍使用的功能,所以,在本文中,将展现如何在C ++应用程序中将Word DOC/DOCX转换为PDF。若是你尚未用过C ++版Aspose.Words能够点击这里下载最新版测试。测试
与此同时,Aspose.Words也提供.NET和Java等多个语言平台的支持,功能很是强大。spa
本文介绍了如下Word到PDF的转换:orm
使用Aspose.Words for C ++,将Word文档转换为PDF就像饼同样简单。如下是将DOC / DOCX文件转换为PDF的步骤。对象
下面的代码示例演示如何在C ++中将DOCX转换为PDF。blog
// Load the document from disk. System::SharedPtrdoc = System::MakeObject( 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.";
输入文字文件索引
转换后的PDF文档文档
PDF格式支持各类PDF标准,包括PDF / A,PDF / E等。在某些状况下,须要将Word文件转换为特定的标准,例如PDF / A-1a。在这种状况下,Aspose.Words for C ++容许为转换后的PDF设置所需的PDF标准。如下是在Word中将PDF标准设置为PDF转换的步骤:get
下面的代码示例演示如何使用PDF / A-1a标准将Word DOCX转换为PDF。it
// Load the document from disk. System::SharedPtrdoc = System::MakeObject( u"Word.docx"); // Set the output PDF path System::String outputPath = u"DOCX-to-PDFA.pdf"; // Set PDF options System::SharedPtroptions = System::MakeObject(); 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::SharedPtrdoc = System::MakeObject( u"Word.docx"); // Set the output PDF path System::String outputPath = u"DOCX-to-PDF.pdf"; // Set PDF options System::SharedPtroptions = System::MakeObject(); 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::SharedPtrdoc = System::MakeObject( u"Word.docx"); // Set the output PDF path System::String outputPath = u"DOCX-to-PDF.pdf"; // Set PDF options System::SharedPtroptions = System::MakeObject(); // Set JPEG quality options->set_JpegQuality(100); // Save the document in PDF format doc->Save(outputPath, options);
若是您有任何疑问或需求,请随时加入Aspose技术交流群(642018183),咱们很高兴为您提供查询和咨询。