翻譯|使用教程|編輯:胡濤|2022-08-17 11:39:30.560|閱讀 183 次
概述:本文介紹了如何從 Java 中的 DOC 中提取圖像。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
圖像通常用于表示 Word DOC 文檔中的重要信息。在文本旁邊包含圖像使內(nèi)容更具吸引力。在某些情況下,您可能需要以編程方式提取 DOC 文檔中嵌入的圖像。為此,本文介紹了如何從 Java 中的 DOC 中提取圖像。
Aspose.Words for Java是一個(gè)功能強(qiáng)大且功能豐富的 API,用于創(chuàng)建、操作和轉(zhuǎn)換 MS Word 文檔。因此,我們將使用此 API 從 DOC 文檔中提取圖像。您可以使用以下 Maven 配置下載API 的 JAR 或?qū)⑵浒惭b到您的 Java 應(yīng)用程序中。
<repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>//repository.aspose.com/repo/</url> </repository> <dependency> <groupId>com.aspose</groupId> <artifactId>aspose-words</artifactId> <version>21.11</version> <type>pom</type> </dependency>
DOC 文檔中的圖像使用形狀對(duì)象表示。因此,要檢索圖像,您必須處理文檔中的每個(gè)形狀。以下是從 Java 中的 DOC 文件中提取圖像的步驟。
以下代碼示例展示了如何從 Java 中的 DOC 文檔中提取圖像。
// Load Word document Document doc = new Document("Document.docx"); // Get all the shapes NodeCollection<Shape> shapes = (NodeCollection<Shape>) doc.getChildNodes(NodeType.SHAPE, true); int imageIndex = 0; // Loop through the shape collection for (Shape shape : shapes) { // Check if shape has image if (shape.hasImage()) { // Extract and save the image String imageFileName = String.format( "Image.ExportImages.{0}_out_{1}", imageIndex, FileFormatUtil.imageTypeToExtension(shape.getImageData().getImageType())); shape.getImageData().save(dataDir + imageFileName); imageIndex++; } }
在本文中,您學(xué)習(xí)了如何在 Java 中從 DOC 文檔中提取圖像。此外,代碼示例還展示了如何從 DOC 文件中提取圖像并將其保存到所需位置。此外,Aspose.Words for Java 提供了廣泛的文檔操作功能。
歡迎下載|體驗(yàn)更多Aspose產(chǎn)品
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn