翻譯|使用教程|編輯:胡濤|2023-03-20 10:28:57.713|閱讀 219 次
概述:在本文中,我將向您展示如何在C++應(yīng)用程序中將Word DOC/DOCX 轉(zhuǎn)換為 PDF。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Aspose.Words 是一種高級(jí)Word文檔處理API,用于執(zhí)行各種文檔管理和操作任務(wù)。API支持生成,修改,轉(zhuǎn)換,呈現(xiàn)和打印文檔,而無需在跨平臺(tái)應(yīng)用程序中直接使用Microsoft Word。此外,
Aspose API支持流行文件格式處理,并允許將各類文檔導(dǎo)出或轉(zhuǎn)換為固定布局文件格式和最常用的圖像/多媒體格式。
再次歡迎來到文件格式 API 主頁!最近,我寫了幾篇博文來介紹在.NET(使用 C#)和Java應(yīng)用程序中以編程方式將 Word (DOC/DOCX) 轉(zhuǎn)換為 PDF 的各種場(chǎng)景。由于這是一個(gè)流行和廣泛使用的特性,我想也為 C++ 涵蓋它。因此,在本文中,我將向您展示如何在C++應(yīng)用程序中將Word DOC/DOCX 轉(zhuǎn)換為 PDF。本文介紹了以下 Word 到 PDF 的轉(zhuǎn)換:
Aspose.Words for C++是一個(gè)高級(jí)庫,無需 MS Word 即可在 C++ 應(yīng)用程序中創(chuàng)建和操作 Word 文檔格式。您可以通過NuGet安裝它,也可以下載包含庫文件以及準(zhǔn)備運(yùn)行源代碼示例的完整包。
使用 Aspose.Words for C++ 將 Word 文檔轉(zhuǎn)換為 PDF 非常簡(jiǎn)單。以下是將 DOC/DOCX 文件轉(zhuǎn)換為 PDF 的步驟。
以下代碼示例顯示了如何在 C++ 中將 DOCX 轉(zhuǎn)換為 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文檔
轉(zhuǎn)換后的 PDF 文檔
PDF 格式支持各種 PDF 標(biāo)準(zhǔn),包括 PDF/A、PDF/E 等。當(dāng)您需要將 Word 文件轉(zhuǎn)換為特定標(biāo)準(zhǔn)(如 PDF/A-1a)時(shí),可能會(huì)有這種情況。在這種情況下,Aspose.Words for C++ 允許您為轉(zhuǎn)換后的 PDF 設(shè)置所需的 PDF 標(biāo)準(zhǔn)。以下是在Word轉(zhuǎn)PDF中設(shè)置PDF標(biāo)準(zhǔn)的步驟:
以下代碼示例顯示了如何將 Word DOCX 轉(zhuǎn)換為符合 PDF/A-1a 標(biāo)準(zhǔn)的 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.";
您也可以只轉(zhuǎn)換選定的頁面,而不是將整個(gè) Word 轉(zhuǎn)換為 PDF。以下是僅將所需的 Word 頁面轉(zhuǎn)換為 PDF 的步驟:
以下代碼示例顯示了如何在 C++ 中將選定的 DOCX 頁面轉(zhuǎn)換為 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()方法應(yīng)用文本和圖像壓縮。以下代碼示例顯示了在 C++ 中將 DOCX 轉(zhuǎn)換為 PDF 時(shí)如何應(yīng)用壓縮。
// 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 中創(chuàng)建 MS Word 編輯器 ,要是您還有其他關(guān)于產(chǎn)品方面的問題,歡迎咨詢我們,或者加入我們官方技術(shù)交流群。
歡迎下載|體驗(yàn)更多Aspose產(chǎn)品
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@ke049m.cn