1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Word处理控件Aspose.Words功能演示:在 Java 中将 DOC 或 DOCX 转换为 JPG

Word处理控件Aspose.Words功能演示:在 Java 中将 DOC 或 DOCX 转换为 JPG

时间:2020-02-08 01:12:51

相关推荐

Word处理控件Aspose.Words功能演示:在 Java 中将 DOC 或 DOCX 转换为 JPG

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

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

在各种情况下,我们需要以编程方式将 MS Word DOC/DOCX 显示到我们的应用程序中。在这种情况下,最方便的方法之一是从 DOC 或 DOCX 转换为 JPG 格式。为此,在本文中,您将学习如何在 Java中将DOC或DOCX文件转换为JPG。此外,我们将介绍如何使用不同的选项自定义 DOC 到 JPG 的转换。

Aspose.Words 最新下载(qun:761297826)/product/564/download

Java API for DOCX DOCX to JPG - 免费下载

Aspose.Words for Java是一个功能丰富的 API,用于在基于 Java 的应用程序中创建、编辑或转换 MS Word 文档。我们将使用此 API 将 DOC/DOCX 转换为 JPG。您可以下载API 的 JAR 或使用以下 Maven 配置安装它:

存储库:

<repository><id>AsposeJavaAPI</id><name>Aspose Java API</name><url>/repo/</url></repository>

依赖:

<dependency><groupId>com.aspose</groupId><artifactId>aspose-words</artifactId><version>22.4</version><classifier>jdk17</classifier></dependency>

在 Java 中将 DOC 转换为 JPG

您可以根据需要将 DOC/DOCX 转换为 JPG、PNG、BMP、GIF 或 TIFF 图像。要设置输出图像格式,使用SaveFormat枚举。让我们在 Java 中将 DOCX 文件转换为 JPG。

使用Document类加载 DOCX 文件。创建ImageSaveOptions类的实例并指定输出图像格式。循环浏览文档中的页面。使用Document.save(string, ImageSaveOptions)方法将 DOCX 中的每一页转换为 JPG 。

以下代码示例展示了如何在 Java 中将 DOCX 转换为 JPG。

// load documentDocument doc = new Document("calibre.docx");// set output image format using SaveFormatvar options = new ImageSaveOptions(SaveFormat.JPEG);// loop through pages and convert them to JPG imagesfor (int pageNumber = 0; pageNumber < doc.getPageCount(); pageNumber++){// Save page as JPGoptions.setPageSet(new PageSet(pageNumber));doc.save(pageNumber + "_page.jpg", options);}

Java DOCX 到 JPG - 自定义

您还可以使用不同的选项自定义 DOC 到 PNG 的转换。例如,您可以设置水平分辨率、垂直分辨率、整体分辨率、比例、像素格式、亮度、颜色模式、对比度等。以下是在Java中自定义DOC到JPG的步骤。

使用Document类加载 DOC 文件。创建ImageSaveOptions类的实例并指定输出图像格式。使用ImageSaveOptions对象设置所需的选项,例如亮度、对比度等。循环浏览文档中的页面。使用Document.save(string, ImageSaveOptions)方法将每个页面转换为 JPG 。

以下代码示例显示了如何使用不同的选项自定义 Java DOC 到 JPG 的转换。

// load documentDocument doc = new Document("calibre.docx");// set output image format using SaveFormatvar options = new ImageSaveOptions(SaveFormat.JPEG);// change the image's brightness and contrast// both are on a 0-1 scale and are at 0.5 by defaultoptions.setImageBrightness(0.30f);options.setImageContrast(0.7f);// change the horizontal resolution// the default value for these properties is 96.0, for a resolution of 96dpioptions.setHorizontalResolution(72f);// loop through pages and convert them to JPG imagesfor (int pageNumber = 0; pageNumber < doc.getPageCount(); pageNumber++){// Save page as JPGoptions.setPageSet(new PageSet(pageNumber));doc.save(pageNumber + "_page.jpg", options);}

结论

在本文中,您学习了如何在 Java 中将 Word DOC/DOCX 转换为 JPG。此外,您还了解了如何使用不同的选项自定义 DOC 到 JPG 的转换。除此之外,您可以使用文档探索 Aspose.Words for Java 的其他功能。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。