翻譯|使用教程|編輯:胡濤|2022-06-30 13:39:09.510|閱讀 202 次
概述:本文介紹了如何使用 Java 從 Word 文檔中提取圖像。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
圖像通常用于表示 Word 文檔中的重要信息。在文本旁邊包含圖像使內容更具吸引力。在某些情況下,您可能需要以編程方式提取嵌入在 Word 文檔中的圖像。為此,本文介紹了如何使用 Java 從 Word 文檔中提取圖像。
Aspose.Words for . Python 最新下載
Aspose.Words for Java是一個功能強大且功能豐富的 API,用于創建、操作和轉換 MS Word 文檔。因此,我們將使用此 API 從 MS Word DOCX/DOC 文檔中提取圖像。您可以使用以下 Maven 配置下載API 的 JAR 或將其安裝到您的 Java 應用程序中。
<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>
Word 文檔中的圖像使用形狀對象表示。因此,要檢索圖像,您必須處理文檔中的每個形狀。以下是從 Java 中的 Word DOCX 文檔中提取圖像的步驟。
以下代碼示例展示了如何從 Java 中的 DOCX 文檔中提取圖像。
// 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++; } }
在本文中,您學習了如何使用 Java 從 Word 文檔中提取圖像。此外,代碼示例還展示了如何從 DOCX 文件中提取圖像并將其保存到所需位置。此外,Aspose.Words for Java 提供了廣泛的文檔操作功能。此外,您可以通過我們的論壇提出您的問題也可以通過在線客服聯系我們。
歡迎下載|體驗更多Aspose產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn