Word处理控件Aspose.Words功能演示:使用 C++ 将 Word 文档转换为多页 TIFF 图像

Aspose.Words 是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。此外,

Aspose API支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。

Aspose.words 最新下载(qun:761297826)icon-default.png?t=N3I4https://www.evget.com/product/4116/download

将 Word 文档另存为多页 TIFF

您可能需要对 Word 文档(例如 DOCX、DOC、RTF 等)执行的一项有用操作是转换为图像文件。例如,如果您必须以可读和可打印但不可编辑的格式呈现您的 Word 文档(例如,为了在 Web 上发布)。您可以使用的一种简单方法是转换为多页 TIFF 文件。请参考以下文章了解如何使用 Aspose.Words for C++ 将 Word 文档转换为 TIFF 格式:
将 Word 文档转换为多页 TIFF 图像

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// Save the document as multipage TIFF.
doc.Save(dataDir + "TestFile Multipage TIFF_out.tiff");

使用 C++ 将图像转换为 PDF

现在可以使用 Aspose.Words for C++ API 从图像创建 PDF 文档。以下文章中提到的代码示例显示了使用 Aspose.Words for C++ 是多么容易。该代码允许将单帧图像(例如 JPEG、PNG、BMP、EMF 或 WMF)以及多帧 TIFF 图像和 GIF 转换为 PDF。
将图像转换为 PDF

使用 C++ 控制 TIFF 二值化的阈值

将灰度图像中包含的信息从 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);

使用 C++ 将图像保存为每像素一位

下面的代码示例演示了如何通过将 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);

使用 C++ 使用密码加密 DOC 或 DOT 文件

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);

使用 C++ 使用密码加密 DOCX 文件

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 图像 ,要是您还有其他关于产品方面的问题,欢迎咨询我们,或者加入我们官方技术交流群。

猜你喜欢

转载自blog.csdn.net/m0_67129275/article/details/130482352