在这个简短的主题中,我们将详细说明如何使用 C++** 将 Word 转换为 TIFF。您可以使用 C++ 加载 DOCX 或 DOC 格式的输入 Word 文档。您可能需要使用 C++ 将 Word 文档转换为 TIFF,以使用简单的代码和少量 API 调用来预览文档的内容。
使用 C++ 将 Word 转换为 TIFF 的步骤
- 使用 NuGet 包管理器工具配置 Aspose.Words.Cpp
- 添加对 Aspose::Words 和 Aspose::Words::Saving 命名空间的引用
- 初始化 Document Class 实例以加载文档以创建 TIFF 文件
- 创建 ImageSaveOptions 类的对象并设置不同的属性
- 使用 Save 方法将输出文件写入 TIFF 图像
在这些步骤中,我们已经注意到如何将 Word 文档导出到 C++ 中的 TIFF。您可以设置不同的属性来控制 Word 到 TIFF 的转换过程。例如,您可以指定输出图像的压缩和颜色模式,以将输出文件创建为灰度或彩色图像。
使用 C++ 将 Word 文档转换为 TIFF 的代码
#pragma once | |
#include <cstdint> | |
#include <iostream> | |
#include <Aspose.Words.Cpp/Document.h> | |
#include <Aspose.Words.Cpp/License.h> | |
#include <Aspose.Words.Cpp/Saving/ImageSaveOptions.h> | |
#include <system/exceptions.h> | |
using System::MakeObject; | |
using System::SharedPtr; | |
using System::String; | |
using namespace Aspose::Words; | |
using namespace Aspose::Words::Saving; | |
void DOCXtoTIFF() | |
{ | |
// Set license | |
System::String LicFilePath = u"Aspose.Total.CPP.lic"; | |
SharedPtr<License> WordsCPPLicenseForDOCXtoTIFF = System::MakeObject<License>(); | |
WordsCPPLicenseForDOCXtoTIFF->SetLicense(LicFilePath); | |
// Instantiate Document class to load document for converting to TIFF | |
SharedPtr<Document> doc = MakeObject<Document>(u"Test.docx"); | |
// Initilaize ImageSaveOptions to convert DOCX to TIFF image | |
SharedPtr<ImageSaveOptions> saveOptions = MakeObject<ImageSaveOptions>(SaveFormat::Tiff); | |
saveOptions->set_TiffCompression(TiffCompression::Lzw); | |
saveOptions->set_ImageColorMode(ImageColorMode::Grayscale); | |
// Save output TIFF image file | |
doc->Save(u"Test.tiff", saveOptions); | |
} |
在上面的代码片段中,首先我们使用 Document 类 加载输入 Word 文件,然后使用 ImageSaveOptions 类 为输出图像设置不同的首选项。最后,我们调用 Save 方法来编写高保真渲染的输出图像。您无需安装 MS Word 或任何其他应用程序即可使用 C++ 将 Word 转换为 TIFF 文件。
在上一个主题中,我们查看了 如何在 C++ 中创建 DOCX。但是,在本主题中,我们的重点是将 Word 转换为 C++ 中的 TIFF 格式。