在共享文档之前,通常使用Word到PDF的转换。可以使用各种在线Word到PDF转换器,可以转换单个或有限数量的Word文档。但是,随着新兴的MS Word自动化和 告生成解决方案,Word到PDF的自动转换已成为系统的重要组成部分。同时,需要自动完成DOC /DOCX到PDF的批量转换,以减少时间和精力。
- 简单的Word DOC / DOCX转换为C ++中的PDF。
- DOCX到具有特定标准的PDF,例如PDF 1.5,PDF / A-1a等。
- 将DOCX的选定页面转换为PDF。
- 将DOCX中的图像/文本压缩应用于PDF转换。
①在C ++中将Word DOC / DOCX转换为PDF
使用Aspose.Words for C ++,将Word文档转换为PDF就像饼一样简单。以下是将DOC / DOCX文件转换为PDF的步骤。
- 创建Document类的对象,并使用Word文档的路径对其进行初始化。
- 调用Document-> Save()方法将文档另存为PDF。
下面的代码示例演示如何在C ++中将DOCX转换为PDF。
// Load the document from disk.System::SharedPtrdoc = System::MakeObject( u"Word.docx");// Set the output PDF pathSystem::String outputPath = u"DOCX-to-PDF.pdf";// Convert DOCX to PDFdoc->Save(outputPath);std::cout << "Converted DOCX to PDF successfuly.";
输入文字文件
转换后的PDF文档

②将DOCX转换为C ++中的PDF / A或其他PDF标准
PDF格式支持各种PDF标准,包括PDF / A,PDF / E等。在某些情况下,需要将Word文件转换为特定的标准,例如PDF / A-1a。在这种情况下,Aspose.Words for C ++允许为转换后的PDF设置所需的PDF标准。以下是在Word中将PDF标准设置为PDF转换的步骤:
- 创建一个Document类的对象,并使用DOCX文件的路径对其进行初始化。
- 创建PdfSaveOptions类的对象,并使用PdfSaveOptions-> set_Compliance()方法设置PDF遵从性。
- 调用Document-> Save()方法将文档另存为PDF。
下面的代码示例演示如何使用PDF / A-1a标准将Word DOCX转换为PDF。
// Load the document from disk.System::SharedPtrdoc = System::MakeObject( u"Word.docx");// Set the output PDF pathSystem::String outputPath = u"DOCX-to-PDFA.pdf";// Set PDF optionsSystem::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.";
③在C ++中将单词的选定页面转换为PDF
可以只转换选定的页面,而不是将整个Word转换为PDF。以下是仅将所需的Word页面转换为PDF的步骤:
- 使用Document类加载Word文档。
- 使用PdfSaveOptions-> set_PageIndex()方法设置起始页的索引。
- 使用PdfSaveOptions-> set_PageCount()方法设置要转换的页面数。
- 使用Document-> Save()方法将文档另存为PDF 。
以下代码示例显示了如何在C ++中将DOCX的选定页面转换为PDF。
// Load the document from disk.System::SharedPtrdoc = System::MakeObject( u"Word.docx");// Set the output PDF pathSystem::String outputPath = u"DOCX-to-PDF.pdf";// Set PDF optionsSystem::SharedPtroptions = System::MakeObject();options->set_PageIndex(1);options->set_PageCount(2);// Save the document in PDF format.doc->Save(outputPath, options);
④将DOCX中的图像/文本压缩应用于PDF转换
可以压缩生成的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 pathSystem::String outputPath = u"DOCX-to-PDF.pdf";// Set PDF optionsSystem::SharedPtroptions = System::MakeObject();// Set JPEG qualityoptions->set_JpegQuality(100);// Save the document in PDF formatdoc->Save(outputPath, options);
还想要更多吗可以点击阅读【2019 · Aspose最新资源整合】,查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!