翻譯|使用教程|編輯:胡濤|2023-03-20 10:28:57.713|閱讀 211 次
概述:在本文中,我將向您展示如何在C++應用程序中將Word DOC/DOCX 轉換為 PDF。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
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@fc6vip.cn