Java를 사용하여 PowerPoint 프레젠테이션에 텍스트 워터마크를 추가하는 방법

발행: (2025년 12월 3일 오전 11:08 GMT+9)
7 min read
원문: Dev.to

Source: Dev.to

Spire.Presentation for Java: 소개 및 설치

Spire.Presentation for Java는 Java 애플리케이션이 PowerPoint 프레젠테이션을 생성, 읽기, 쓰기 및 변환할 수 있도록 해주는 강력하고 기능이 풍부한 API입니다. 슬라이드, 도형, 텍스트, 이미지 및 워터마크 추가와 같은 프레젠테이션 요소를 관리하는 광범위한 기능을 제공합니다. 이 라이브러리는 복잡한 PowerPoint 자동화 작업을 간소화하여 개발자에게 매우 유용한 도구가 됩니다.

Spire.Presentation을 프로젝트에 통합하는 가장 간단한 방법은 Maven 의존성을 추가하는 것입니다. 이렇게 하면 필요한 모든 라이브러리가 자동으로 관리되고 빌드에 포함됩니다.

Maven 의존성

<!-- Repository definition -->
<repository>
    <id>e-iceblue</id>
    <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>

<!-- Dependency -->
<dependency>
    <groupId>com.e-iceblue</groupId>
    <artifactId>spire.presentation</artifactId>
    <version>10.11.4</version>
</dependency>

Maven을 사용하지 않는 경우, E‑iceblue 웹사이트에서 JAR 파일을 직접 다운로드하여 프로젝트의 빌드 경로에 수동으로 추가할 수도 있습니다. 그러나 의존성 관리를 쉽게 하기 위해 일반적으로 Maven 사용을 권장합니다.


Java를 사용하여 PowerPoint에 단일 라인 텍스트 워터마크 추가하기

단일 라인 텍스트 워터마크는 “CONFIDENTIAL”, “DRAFT”, “INTERNAL USE ONLY” 와 같은 미묘하면서도 명확한 브랜딩이나 콘텐츠 상태 표시용으로 이상적입니다. 이 방법은 일반적으로 워터마크를 슬라이드 대각선에 배치하여 주요 콘텐츠를 가리지 않으면서 가시성을 확보합니다.

단계

  1. PowerPoint 파일 생성 및 로드Presentation 객체를 인스턴스화하고 Presentation.loadFromFile()을 호출합니다.
  2. 워터마크 크기 정의 – 텍스트 상자의 너비와 높이를 설정합니다.
  3. 사각형 도형 만들기Rectangle2D.Double을 사용해 슬라이드 크기에 상대적인 위치에 도형을 배치합니다.
  4. 도형을 슬라이드에 추가Presentation.getSlides().get(0).getShapes().appendShape()를 사용해 첫 번째 슬라이드에 사각형을 추가합니다.
  5. 도형 스타일 맞춤 – 테두리, 채우기 투명도, 회전 각도 및 정렬을 조정합니다.
  6. 워터마크 텍스트 추가 및 서식 지정IAutoShape.getTextFrame().setText()로 텍스트를 설정한 뒤 TextRange(폰트, 크기, 색상, 투명도)를 스타일링합니다.
  7. 프레젠테이션 저장Presentation.saveToFile()로 업데이트된 파일을 내보냅니다.

코드 예시

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import java.awt.*;
import java.awt.geom.Rectangle2D;

public class InsertSingleWatermark {
    public static void main(String[] args) throws Exception {

        // Create a Presentation object and load a sample file
        Presentation presentation = new Presentation();
        presentation.loadFromFile("sample.pptx");

        // Set the width and height of watermark string
        int width = 400;
        int height = 300;

        // Define the position and size of shape
        Rectangle2D.Double rect = new Rectangle2D.Double(
                (presentation.getSlideSize().getSize().getWidth() - width) / 2,
                (presentation.getSlideSize().getSize().getHeight() - height) / 2,
                width, height);

        // Add the shape to the first slide
        IAutoShape shape = presentation.getSlides().get(0).getShapes()
                .appendShape(ShapeType.RECTANGLE, rect);

        // Set the style of shape
        shape.getFill().setFillType(FillFormatType.NONE);
        shape.getShapeStyle().getLineColor().setColor(Color.white);
        shape.setRotation(-45);
        shape.getLocking().setSelectionProtection(true);
        shape.getLine().setFillType(FillFormatType.NONE);

        // Add text to shape
        shape.getTextFrame().setText("Confidential");
        PortionEx textRange = shape.getTextFrame().getTextRange();

        // Set the style of the text range
        textRange.getFill().setFillType(FillFormatType.SOLID);
        textRange.setFontHeight(50);
        Color color = new Color(237, 129, 150, 200); // RGBA with transparency
        textRange.getFill().getSolidColor().setColor(color);

        // Save the result document
        presentation.saveToFile("output/SingleWatermark.pptx", FileFormat.PPTX_2010);
        presentation.dispose();
    }
}

위 스니펫은 프레젠테이션을 로드하고, 텍스트 상자를 만든 뒤 텍스트와 서식을 설정(색상, 폰트 크기, 투명도 포함)하고, 회전시킨 뒤 최종적으로 프레젠테이션을 저장하는 과정을 보여줍니다. 투명도와 회전은 적절한 워터마크 효과를 얻기 위해 핵심 요소입니다.


Java를 사용하여 PowerPoint에 타일형 텍스트 워터마크(다중 라인) 추가하기

보다 강력한 콘텐츠 보호 또는 전면적인 브랜딩을 위해 타일형 워터마크는 슬라이드 전체에 반복되는 텍스트를 배치합니다. 이렇게 하면 워터마크를 잘라내거나 무시하기가 어려워지며, 특히 민감한 문서에 유용합니다.

단계

  1. PowerPoint 프레젠테이션 로드Presentation 객체를 생성하고 loadFromFile()을 호출합니다.
  2. 워터마크 텍스트 준비 및 크기 측정 – 반복할 문자열을 정의하고 그 치수를 계산합니다.
  3. 반복 워터마크 도형 추가 – 시작 좌표를 초기화하고 슬라이드 레이아웃을 순회하면서 appendShape()로 사각형 도형을 삽입해 여러 워터마크를 배치합니다.
  4. 사각형 도형 서식 지정 – 채우기 투명도 적용, 테두리 제거, 회전 설정 등으로 워터마크를 은은하게 만듭니다.
  5. 각 도형에 텍스트 적용IAutoShape.getTextFrame().setText()로 텍스트를 설정하고 TextRange를 가져와 추가 스타일링을 수행합니다.
  6. 워터마크 텍스트 서식 지정 – 폰트 크기, 색상, 불투명도, 간격 및 회전을 맞춤 설정합니다.
  7. 파일 저장Presentation.saveToFile()로 최종 버전을 내보냅니다.

코드 예시

import com.spire.pdf.graphics.PdfTrueTypeFont;
import com.spire.presentat
// (The remainder of the example code should follow the same pattern as the single‑line watermark,
// creating multiple shapes in a loop, setting their text, styling, and then saving the file.)

Note: The provided snippet is incomplete; developers should extend it by looping over the slide area, creating shapes, applying the desired text and styling, and then saving the presentation as shown in the single‑line example.

Back to Blog

관련 글

더 보기 »

Java OOPS 개념

Forem 로고https://media2.dev.to/dynamic/image/width=65,height=,fit=scale-down,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%...