翻譯|使用教程|編輯:胡濤|2023-05-04 09:41:08.067|閱讀 115 次
概述:本文將介紹如何使用 C++ 將 Word 文檔轉換為多頁 TIFF 圖像,歡迎查閱~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Aspose.Words 是一種高級Word文檔處理API,用于執行各種文檔管理和操作任務。API支持生成,修改,轉換,呈現和打印文檔,而無需在跨平臺應用程序中直接使用Microsoft Word。此外,
Aspose API支持流行文件格式處理,并允許將各類文檔導出或轉換為固定布局文件格式和最常用的圖像/多媒體格式。
您可能需要對 Word 文檔(例如 DOCX、DOC、RTF 等)執行的一項有用操作是轉換為圖像文件。例如,如果您必須以可讀和可打印但不可編輯的格式呈現您的 Word 文檔(例如,為了在 Web 上發布)。您可以使用的一種簡單方法是轉換為多頁 TIFF 文件。請參考以下文章了解如何使用 Aspose.Words for C++ 將 Word 文檔轉換為 TIFF 格式:
將 Word 文檔轉換為多頁 TIFF 圖像
// For complete examples and data files, please go to //github.com/aspose-words/Aspose.Words-for-.NET // Save the document as multipage TIFF. doc.Save(dataDir + "TestFile Multipage TIFF_out.tiff");
現在可以使用 Aspose.Words for C++ API 從圖像創建 PDF 文檔。以下文章中提到的代碼示例顯示了使用 Aspose.Words for C++ 是多么容易。該代碼允許將單幀圖像(例如 JPEG、PNG、BMP、EMF 或 WMF)以及多幀 TIFF 圖像和 GIF 轉換為 PDF。
將圖像轉換為 PDF
將灰度圖像中包含的信息從 256 級灰度減少為黑白 2 級并將其轉換為二值圖像的過程就是二值化。當文檔轉換為 TIFF 文件格式時,您可以使用 ImageSaveOptions.ThresholdForFloydSteinbergDithering 屬性控制 TIFF 二值化的閾值。該屬性的默認值為 128。值越高,圖像越暗。以下代碼示例顯示如何使用此屬性來控制 TIFF 二值化的閾值。
System::SharedPtr<ImageSaveOptions> options = System::MakeObject<ImageSaveOptions>(SaveFormat::Tiff); options->set_TiffCompression(TiffCompression::Ccitt3); options->set_ImageColorMode(ImageColorMode::Grayscale); options->set_TiffBinarizationMethod(ImageBinarizationMethod::FloydSteinbergDithering); options->set_ThresholdForFloydSteinbergDithering(254); System::String outputPath = outputDataDir + u"ImageColorFilters.ExposeThresholdControlForTiffBinarization.tiff"; doc->Save(outputPath, options);
下面的代碼示例演示了如何通過將 PixelFormat 設置為 Format1bppIndexed 將圖像保存為每像素一位。
System::SharedPtr<ImageSaveOptions> opt = System::MakeObject<ImageSaveOptions>(SaveFormat::Png); opt->set_PageIndex(1); opt->set_ImageColorMode(ImageColorMode::BlackAndWhite); opt->set_PixelFormat(ImagePixelFormat::Format1bppIndexed); System::String outputPath = outputDataDir + u"ImageColorFilters.SaveImageToOnebitPerPixel.png"; doc->Save(outputPath, opt);
DocSaveOptions 類用于在將文檔保存為 DOC 或 DOT 格式時指定其他選項。使用此類,您可以為加密文檔設置密碼,并在保存文檔時忽略 RoutingSlip 數據。下面給出的代碼示例顯示了如何設置密碼以使用 RC4 加密方法加密文檔。
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Document.doc"); System::SharedPtr<DocSaveOptions> docSaveOptions = System::MakeObject<DocSaveOptions>(); docSaveOptions->set_Password(u"password"); System::String outputPath = outputDataDir + u"WorkingWithDoc.EncryptDocumentWithPassword.doc"; doc->Save(outputPath, docSaveOptions);
OoXMLSaveOptions 類提供了一個機會來保存任何使用密碼加密的文檔。使用此類,您可以在保存文檔時使用 OoxmlSaveOptions.Password 屬性設置密碼。下面的代碼示例演示了如何設置密碼并將文檔保存為 DOCX 格式。
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Document.doc"); System::SharedPtr<OoxmlSaveOptions> ooxmlSaveOptions = System::MakeObject<OoxmlSaveOptions>(); ooxmlSaveOptions->set_Password(u"password"); System::String outputPath = outputDataDir + u"WorkingWithOoxml.EncryptDocxWithPassword.docx"; doc->Save(outputPath, ooxmlSaveOptions);
以上便是如何使用 C++ 將 Word 文檔轉換為多頁 TIFF 圖像 ,要是您還有其他關于產品方面的問題,歡迎咨詢我們,或者加入我們官方技術交流群。
歡迎下載|體驗更多Aspose產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn