GroupDocs.Watermark を使用した Java での図形抽出方法

When you need to 形状の抽出方法 from a Visio‑style diagram programmatically, the GroupDocs.Watermark library gives you a clean, Java‑first way to pull every detail—dimensions, positions, embedded images, and even the text inside each shape. In this tutorial you’ll see exactly 形状の抽出方法, why it matters, and step‑by‑step code you can copy into your project.

クイック回答

  • 形状抽出を扱うライブラリは何ですか? GroupDocs.Watermark for Java
  • 必要な Java バージョンはどれですか? JDK 8 or higher
  • 形状から画像データを取得できますか? Yes – use shape.getImage()
  • 形状内のテキストにアクセスできますか? Absolutely, via shape.getText()
  • 本番環境でライセンスが必要ですか? A valid GroupDocs.Watermark license is required

はじめに

Managing complex diagrams often requires accessing detailed information about their components, such as shapes and images. If you’ve ever needed to programmatically retrieve data like dimensions, positions, or text associated with diagram shapes using Java, this tutorial is for you. Leveraging the power of the GroupDocs.Watermark library can streamline this process in a Java application. In this guide, we’ll walk through 形状の抽出方法 from a diagram file and also show you how to extract image from shape and extract text from shape.

“形状の抽出方法” とは何ですか?

Extracting shapes means reading the diagram’s internal objects (pages, shapes, images, text) so you can analyze, transform, or reuse them in other applications—perfect for automation, reporting, or integration with CAD tools.

なぜ GroupDocs.Watermark を形状抽出に使用するのか?

  • Full format support – works with VSDX, VDX, and many other diagram types.
  • Rich object model – gives direct access to shape geometry, images, and text.
  • No external dependencies – pure Java, easy to embed in Maven projects.

前提条件

  • GroupDocs.Watermark for Java (version 24.11 or later)
  • Java Development Kit (JDK) 8 or higher
  • Maven for dependency management
  • An IDE such as IntelliJ IDEA or Eclipse

GroupDocs.Watermark for Java の設定

Add the library to your Maven pom.xml:

<repositories>
    <repository>
        <id>repository.groupdocs.com</id>
        <name>GroupDocs Repository</name>
        <url>https://releases.groupdocs.com/watermark/java/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.groupdocs</groupId>
        <artifactId>groupdocs-watermark</artifactId>
        <version>24.11</version>
    </dependency>
</dependencies>

You can also download the latest binaries from GroupDocs.Watermark for Java releases.

ライセンス取得手順

  • Free Trial: Download a trial package to evaluate the API.
  • Temporary License: Request a temporary key for extended testing.
  • Purchase: Obtain a full license for production use.

基本的な初期化と設定

import com.groupdocs.watermark.Watermarker;
import com.groupdocs.watermark.contents.DiagramContent;
import com.groupdocs.watermark.options.DiagramLoadOptions;

DiagramLoadOptions diagramLoadOptions = new DiagramLoadOptions();
Watermarker watermarker = new Watermarker("YOUR_DOCUMENT_DIRECTORY/diagram.vsdx", diagramLoadOptions);

形状抽出 – 実装ガイド

コンテンツのロードと取得

// Create load options if necessary
DiagramLoadOptions diagramLoadOptions = new DiagramLoadOptions();
// Initialize watermarker with your document path
Watermarker watermarker = new Watermarker("YOUR_DOCUMENT_DIRECTORY/diagram.vsdx", diagramLoadOptions);
// Retrieve content of the diagram file as a DiagramContent object
DiagramContent content = watermarker.getContent(DiagramContent.class);

形状の反復処理

for (DiagramPage page : content.getPages()) {
    // Process each shape in the current page
}
for (DiagramShape shape : page.getShapes()) {
    if (shape.getImage() != null) {
        // Access and print image-related properties
        System.out.println("Image Width: " + shape.getImage().getWidth());
        System.out.println("Image Height: " + shape.getImage().getHeight());
        System.out.println("Image Size: " + shape.getImage().getData().length);
    }
    
    // Print other shape attributes
    System.out.println("Shape Name: " + shape.getName());
    System.out.println("X Position: " + shape.getX());
    System.out.println("Y Position: " + shape.getY());
    System.out.println("Width: " + shape.getWidth());
    System.out.println("Height: " + shape.getHeight());
    System.out.println("Rotation Angle: " + shape.getRotationAngle());
    System.out.println("Text: " + (shape.getText() != null ? shape.getText() : "No text"));
    System.out.println("Shape ID: " + shape.getId());
}

形状から画像を抽出する方法

The shape.getImage() call returns an object containing the raw bitmap, its dimensions, and the byte array. Use the properties shown above to store the image on disk or feed it into another processing pipeline.

形状からテキストを抽出する方法

The shape.getText() method returns the plain text inside the shape. If the shape contains no text, the method returns null. The sample loop already prints the text, and you can further manipulate it—for example, building an index of all shape labels.

トラブルシューティングのヒント

  • Verify the file path and read permissions.
  • Ensure you are using a supported diagram format (VSDX, VDX, etc.).
  • If a shape appears without expected data, check the library’s release notes for format‑specific quirks.

実用的な活用例

  1. Diagram Analysis: Automatically audit diagrams for compliance by checking shape sizes or missing labels.
  2. Data Visualization: Feed extracted dimensions into a reporting dashboard to visualize layout density.
  3. CAD Integration: Combine shape data with CAD APIs to synchronize design specifications across tools.

パフォーマンスに関する考慮点

  • Close resources: Call watermarker.close() when you’re done to free native resources.
  • Memory management: Large diagrams can consume significant heap; monitor memory and increase -Xmx if needed.
  • Batch processing: Process files in batches and reuse a single Watermarker instance when possible.

結論

By following this guide you now know 形状の抽出方法, how to extract image from shape, and how to extract text from shape using GroupDocs.Watermark for Java. These techniques open the door to automated diagram analysis, reporting, and integration with other engineering systems. As a next step, explore the full API by checking out its documentation and try combining shape extraction with custom business logic.

FAQ セクション

  1. What is GroupDocs.Watermark?

    • A comprehensive Java library designed for watermarking and extracting information from various document formats, including diagrams.
  2. Can I use this library to process all types of diagram files?

    • Yes, but ensure that the file format is supported by checking the API Reference.
  3. How do I extract shape dimensions and positions from a diagram using Java and GroupDocs.Watermark?

    • Load the diagram, access DiagramContent, then iterate shapes to get properties like width, height, X, and Y.
  4. Can GroupDocs.Watermark extract images embedded in diagram shapes with Java?

    • Yes, it provides methods to access image data within shapes, including size and pixel data, useful for analysis or modification.
  5. What are the prerequisites for extracting diagram shape info in Java?

    • Java JDK 8+, Maven setup, GroupDocs.Watermark library (24.11+), and basic Java knowledge are essential for implementation.

最終更新日: 2026-02-13
テスト環境: GroupDocs.Watermark 24.11 for Java
作者: GroupDocs