Java 코드에서 직접 Visio 다이어그램을 생성하면 문서화 워크플로를 간소화하고 수동 그리기 작업을 없앨 수 있습니다. Conholdate.Total for Java은 Visio 파일을 프로그래밍 방식으로 생성할 수 있는 강력한 SDK를 제공합니다. 이 가이드에서는 Java에서 Visio 다이어그램을 만들고, 마스터 템플릿에서 도형을 추가하고, 위치를 지정하며, 텍스트 스타일을 적용합니다. 끝까지 진행하면 Microsoft Visio에서 추가로 편집할 수 있는 바로 열 수 있는 VSDX 파일을 얻게 됩니다.

Visio 다이어그램 생성 요구 사항

Enterprises often need to produce technical schematics, flowcharts, or network diagrams automatically from data sources. Java developers building reporting dashboards, configuration tools, or CI pipelines frequently face the requirement to generate Visio files without manual intervention. The solution must support master‑based shape creation, precise positioning, and text styling that matches existing Visio stencils. Manual drawing in Visio is time‑consuming and error‑prone, especially when diagrams must be regenerated on each build.

접근 방식: Conholdate.Total를 사용한 Visio 다이어그램 생성

Conholdate.Total for Java 은 VSDX 형식을 지원하는 전용 다이어그램 API를 제공합니다. 이를 통해 마스터 스텐실을 로드하고, 해당 마스터에서 도형을 추가하며, XForm 속성을 통해 도형의 위치를 재조정하고, 텍스트를 첨부하고, 미리 정의된 텍스트 스타일을 적용할 수 있으며, 모두 간단한 Java 호출로 수행됩니다. 다이어그램 클래스에 대한 문서는 공식 문서에서 확인할 수 있으며, 전체 API 참조는 API 참조에서 탐색할 수 있습니다. 이 라이브러리를 사용하면 서버 또는 데스크톱 환경에서 전체 Visio 생성 파이프라인을 자동화할 수 있습니다.

솔루션 구축: Java에서 Visio 다이어그램 만들기

다음 단계에서는 Maven 설정부터 최종 VSDX 파일 저장까지 전체 프로세스를 안내합니다.

Maven 종속성 추가 및 클래스 가져오기

먼저 Conholdate Maven 저장소를 구성하고 SDK 종속성을 pom.xml에 추가합니다.

<repositories>
  <repository>
    <id>conholdate-repo</id>
    <name>Conholdate Maven Repository</name>
    <url>https://repository.conholdate.com/repo/</url>
  </repository>
</repositories>

<dependency>
  <groupId>com.conholdate</groupId>
  <artifactId>conholdate-total</artifactId>
  <version>24.9</version>
  <type>pom</type>
</dependency>

이 튜토리얼에서 사용되는 다이어그램 클래스는 com.aspose.diagram 패키지에 있으며, Conholdate.Total for Java 번들의 일부로 제공됩니다:

import com.aspose.diagram.Diagram;
import com.aspose.diagram.Shape;
import com.aspose.diagram.TypeValue;
import com.aspose.diagram.Txt;
import com.aspose.diagram.SaveFileFormat;

다이어그램 초기화 및 마스터 도형 로드

새로운 Diagram 인스턴스를 만든 다음 스텐실 파일을 로드하고 도형의 기반이 될 마스터를 선택합니다. 여기서는 “Basic Shapes.vss” 스텐실에 포함된 내장 “Rectangle” 마스터를 사용합니다.

// Create a new instance of a diagram
Diagram diagram = new Diagram();

// Define the name of the master (template) to be used for creating shapes
String masterName = "Rectangle";
diagram.addMaster("Basic Shapes.vss", masterName);

마스터에서 도형을 추가하고 위치 설정

마스터를 사용하여 다이어그램에 도형을 추가한 다음, addShape가 반환하는 ID로 도형을 찾아 위치를 조정할 수 있습니다.

// Define the dimensions and position for the new shape
double width = 2, height = 2, pinX = 4.25, pinY = 4.5;

// Add a new rectangle shape to the diagram using the specified master
long rectangleId = diagram.addShape(pinX, pinY, width, height, masterName, 0);

// Retrieve the shape by its ID for modification
Shape rectangle = diagram.getPages().get(0).getShapes().getShape(rectangleId);

// Set the position of the shape by modifying its PinX and PinY properties
rectangle.getXForm().getPinX().setValue(5);
rectangle.getXForm().getPinY().setValue(5);

// Set the type of the shape to indicate it is a standard shape
rectangle.setType(TypeValue.SHAPE);

텍스트 추가 및 텍스트 스타일 적용

텍스트 실행을 도형에 연결하고 다이어그램에 미리 정의된 스타일 시트 중 하나를 적용하여 레이블이 문서의 나머지 부분과 일치하도록 합니다.

// Add text to the shape
rectangle.getText().getValue().add(new Txt("Aspose Diagram"));

// Apply a predefined text style to the shape's text
rectangle.setTextStyle(diagram.getStyleSheets().get(3));

다이어그램을 VSDX로 저장

마지막으로, 다이어그램을 Microsoft Visio에서 열 수 있는 VSDX 파일에 저장합니다.

diagram.save("Visio_out.vsdx", SaveFileFormat.VSDX);

Java에서 Visio 다이어그램 만들기 - 전체 작업 샘플 - 완전한 코드 예제

다음 코드는 시작부터 끝까지 전체 워크플로우를 보여줍니다.

import com.aspose.diagram.Diagram;
import com.aspose.diagram.Shape;
import com.aspose.diagram.TypeValue;
import com.aspose.diagram.Txt;
import com.aspose.diagram.SaveFileFormat;

public class CreateVisioDiagram {
    public static void main(String[] args) {
        try {
            // Create a new instance of a diagram
            Diagram diagram = new Diagram();

// Define the name of the master (template) to be used for creating shapes
            String masterName = "Rectangle";
            diagram.addMaster("Basic Shapes.vss", masterName);

// Define the dimensions and position for the new shape
            double width = 2, height = 2, pinX = 4.25, pinY = 4.5;

// Add a new rectangle shape to the diagram using the specified master
            long rectangleId = diagram.addShape(pinX, pinY, width, height, masterName, 0);

// Retrieve the shape by its ID for modification
            Shape rectangle = diagram.getPages().get(0).getShapes().getShape(rectangleId);

// Set the position of the shape by modifying its PinX and PinY properties
            rectangle.getXForm().getPinX().setValue(5);
            rectangle.getXForm().getPinY().setValue(5);

// Set the type of the shape to indicate it is a standard shape
            rectangle.setType(TypeValue.SHAPE);

// Add text to the shape
            rectangle.getText().getValue().add(new Txt("Aspose Diagram"));

// Apply a predefined text style to the shape's text
            rectangle.setTextStyle(diagram.getStyleSheets().get(3));

// Save the modified diagram to a file
            diagram.save("Visio_out.vsdx", SaveFileFormat.VSDX);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Note: 이 코드 예제는 핵심 기능을 보여줍니다. 프로젝트에 사용하기 전에 파일 경로와 구성 값을 실제 환경에 맞게 업데이트하고, 모든 필수 종속성이 올바르게 설치되었는지 확인하며, 개발 환경에서 충분히 테스트하십시오. 문제가 발생하면 공식 문서를 참조하거나 지원 팀에 문의하십시오.

Visio 다이어그램 프로젝트 배포 고려 사항

SDK는 Java 8+ 런타임에서 실행되며, 백엔드 서비스, 배치 작업 또는 데스크톱 유틸리티에 적합합니다. 대형 다이어그램을 생성할 때는 힙 사용량을 모니터링하고 메모리 오버헤드를 줄이기 위해 여러 페이지에 대해 단일 Diagram 인스턴스를 재사용하는 것을 고려하십시오. 프로덕션에서는 유효한 라이선스가 필요합니다; 테스트용 임시 라이선스는 임시 라이선스 페이지에서 얻을 수 있으며, 전체 라이선스는 가격 페이지를 통해 구매할 수 있습니다. 코드를 실행하는 프로세스가 출력 디렉터리에 쓸 수 있는 권한이 있는지 확인하십시오.

결론

Java에서 Visio 다이어그램을 프로그래밍 방식으로 만드는 것이 Conholdate.Total for Java와 함께 간단해집니다. 위 단계들을 따라 하면 마스터 스텐실을 로드하고, VSDX 파일을 생성하며, 도형을 정확히 배치하고, 일관된 텍스트 스타일을 적용할 수 있습니다. 적절한 프로덕션 라이선스를 획득하고, 생성된 다이어그램을 Microsoft Visio에서 테스트하여 레이아웃 정확성을 확인하는 것을 기억하세요. SDK가 준비되면 다양한 엔터프라이즈 시나리오 전반에 걸쳐 다이어그램 생성을 자동화할 수 있습니다.

자주 묻는 질문

  • Java에서 마스터 템플릿을 사용하여 Visio 다이어그램을 만들려면 어떻게 해야 하나요?
    Conholdate.Total for Java에서 제공하는 다이어그램 클래스를 사용하고, addMaster로 스텐실을 로드한 다음, 해당 마스터에서 addShape로 도형을 추가하고, 파일을 VSDX 형식으로 저장합니다.

  • SDK가 Visio 다이어그램에 대해 생성하는 파일 형식은 무엇입니까?
    SDK는 최신 VSDX 형식을 출력하며, 이는 Microsoft Visio와 완전히 호환됩니다.

  • 생성된 Visio 파일을 프로덕션에서 실행하려면 라이선스가 필요합니까?
    예. 가격 페이지에서 프로덕션 라이선스를 얻고 개발 중에는 임시 라이선스를 사용할 수 있습니다.

  • 이 다이어그램 생성을 웹 서비스에 통합할 수 있나요?
    물론입니다. SDK는 순수 Java 라이브러리이므로 Spring Boot 또는 Jakarta EE와 같은 Java 기반 백엔드에서 호출할 수 있습니다.

더 읽기