PDF에 주석 추가
If you need to PDF에 주석 추가 files from a Java application—whether you’re building a contract‑review portal, an e‑learning platform, or a collaborative document editor—this tutorial shows you exactly how to do it with GroupDocs.Annotation. You’ll learn to load PDFs, create area‑style comments, manage resources efficiently, and handle large files without exhausting memory.
빠른 답변
- GroupDocs.Annotation의 주요 목적은 무엇인가요? To add, edit, and manage annotations across many document formats from Java.
- 검토 댓글에 가장 적합한 주석 유형은 무엇인가요?
AreaAnnotation(사용자 지정 메시지와 사용자 메타데이터 포함). - 개발에 라이선스가 필요합니까? 테스트용으로는 무료 체험판을 사용할 수 있지만, 프로덕션에서는 정식 라이선스가 필요합니다.
- 50 MB보다 큰 PDF를 처리할 수 있나요? 예 — 스트리밍, 배치 처리 및 적절한 해제를 사용하여 메모리 사용량을 낮게 유지하십시오.
- 이 라이브러리는 스레드 안전한가요? Instances are not thread‑safe; create a separate
Annotatorper thread.
GroupDocs Annotation이 돋보이는 이유
GroupDocs.Annotation은 다양한 파일 형식을 지원하면서 PDF에 주석을 빠르게 추가할 수 있게 해줍니다. 다음과 같은 기능을 제공합니다:
- 포괄적인 형식 지원 – DOCX, PPTX, XLSX, JPEG, PNG, TIFF 등을 포함한 50개 이상의 입력 및 출력 형식.
- 다양한 주석 팔레트 – 하이라이트, 화살표, 워터마크, 텍스트 교체 및 사용자 정의 도형을 단일 API로 제공.
- 엔터프라이즈 수준 기능 – 내장 라이선스, 확장성 옵션 및 기존 Java 스택과의 원활한 통합.
- 활발한 개발 – 매월 릴리스로 성능 향상(최대 30 % 빠른 렌더링) 및 새로운 주석 유형을 제공합니다.
전제 조건 및 설정 요구 사항
시작하기 전에 필요한 것
- 개발 환경 – JDK 8 이상(Java 11+ 권장), Maven 또는 Gradle, 그리고 선호하는 IDE(IntelliJ IDEA, Eclipse, VS Code).
- 기본 지식 – Java 구문, 파일 I/O 및 Maven 의존성 관리.
- 선택 사항 – PDF 페이지 좌표에 대한 이해와 다른 Java 라이브러리 사용 경험.
Java용 GroupDocs.Annotation 설정
Maven 구성
Add the GroupDocs repository and the Annotation dependency to your pom.xml. Replace 25.2 with the latest version if a newer one is available.
<!-- Maven repository -->
<repository>
<id>groupdocs-repo</id>
<url>https://repo.groupdocs.com/maven2</url>
</repository>
<!-- Annotation dependency -->
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-annotation</artifactId>
<version>25.2</version>
</dependency>
팁: 항상 GroupDocs 웹사이트에서 최신 버전을 확인하십시오. 새로운 릴리스는 대용량 PDF의 메모리 사용량을 최대 20 %까지 줄이는 경우가 많습니다.
라이선스 옵션(실제 의미)
- 무료 체험 – 워터마크가 있는 출력으로 평가에 적합합니다.
- 임시 라이선스 – 30일 동안 제한 없이 사용 가능; 임시 라이선스를 얻으려면 Temporary License를 방문하십시오.
- 정식 라이선스 – 프로덕션 배포에 필요하며, 가격은 배포 규모에 따라 다릅니다.
초기 검증
After adding the dependency, run this tiny test to confirm the library loads correctly:
<repositories>
<repository>
<id>repository.groupdocs.com</id>
<name>GroupDocs Repository</name>
<url>https://releases.groupdocs.com/annotation/java/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-annotation</artifactId>
<version>25.2</version>
</dependency>
</dependencies>
GroupDocs.Annotation을 사용하여 Java에서 PDF 주석 만들기
Load the document, add an AreaAnnotation, and save the result. The following direct answer summarizes the whole workflow:
new Annotator("input.pdf")로 PDF를 로드하고, 사각형과 주석 텍스트를 정의하는 AreaAnnotation을 생성한 뒤, Annotator에 주석을 추가하고 save("output.pdf")을 호출합니다. 이 3단계 패턴은 모든 PDF 크기를 처리하고 리소스가 자동으로 해제되도록 보장합니다.
문서 로드: 파일 경로 이상의 방법
기본 문서 로드
Annotator 클래스는 모든 주석 작업의 진입점입니다. 메모리 내 PDF 문서를 나타내며 주석을 읽고, 수정하고, 저장하는 메서드를 제공합니다.
Annotator annotator = new Annotator("sample.pdf");
실제 상황: 프로덕션에서는 파일 경로가 업로드 폴더, 데이터베이스 블롭 또는 클라우드 스토리지 URL에서 올 수 있습니다. GroupDocs.Annotation은 로컬 파일, InputStream 및 원격 URL을 추가 코드 없이도 받아들입니다.
다양한 입력 소스 처리
바이트 배열이나 HTTP URL에서 PDF를 로드할 수도 있습니다:
import com.groupdocs.annotation.Annotator;
public class SetupVerification {
public static void main(String[] args) {
try {
// This should not throw any ClassNotFoundException
System.out.println("GroupDocs.Annotation version: " +
com.groupdocs.annotation.internal.c.a.a.d());
System.out.println("Setup successful!");
} catch (Exception e) {
System.err.println("Setup failed: " + e.getMessage());
}
}
}
첫 번째 주석 추가
AreaAnnotation 이해하기
AreaAnnotation은 사각형 영역을 강조하고 주석을 첨부할 수 있는 가장 다재다능한 유형입니다. 이동, 크기 조정 및 스타일링이 가능한 디지털 포스트잇과 같습니다.
AreaAnnotation area = new AreaAnnotation();
area.setRectangle(new Rectangle(100, 150, 200, 80)); // x, y, width, height
area.setComment("Review this section for compliance.");
area.setCreator("alice@example.com");
좌표계 설명: PDF 좌표는 왼쪽 하단이 원점이지만, GroupDocs는 UI 프레임워크와 일치하는 왼쪽 상단을 원점으로 사용합니다. 값은 포인트(1/72 인치) 단위로 표현됩니다.
실용적인 주석 예시
중요 텍스트 하이라이트
HighlightAnnotation highlight = new HighlightAnnotation();
highlight.setRectangle(new Rectangle(50, 200, 300, 20));
highlight.setColor(Color.YELLOW);
annotator.add(highlight);
검토 댓글 만들기
AreaAnnotation comment = new AreaAnnotation();
comment.setRectangle(new Rectangle(120, 400, 250, 100));
comment.setComment("Please verify the calculation in this paragraph.");
comment.setCreator("bob@example.com");
annotator.add(comment);
저장 및 리소스 관리
올바른 파일 저장 기법
annotator.save("annotated.pdf");
해제의 중요성: Annotator는 빠른 접근을 위해 PDF 내용을 메모리에 보관합니다. 이를 닫지 않으면 메모리 누수가 발생할 수 있으며, 특히 배치 작업에서 수십 개의 파일을 처리할 때 문제가 됩니다.
향상된 리소스 관리 패턴
try (Annotator annotator = new Annotator("input.pdf")) {
// add annotations here
annotator.save("output.pdf");
}
일반적인 함정 및 회피 방법
파일 경로 및 권한 문제
- 문제: “File not found” 또는 “Access denied”.
- 해결책: 개발 중 절대 경로를 사용하고, 읽기/쓰기 권한을 확인하며, 파일을 열기 전에 존재 여부를 확인하십시오.
File file = new File("C:/docs/input.pdf");
if (!file.exists() || !file.canRead()) {
throw new IllegalArgumentException("File is missing or unreadable.");
}
메모리 관리 실수
- 문제: 많은 PDF를 처리한 후 애플리케이션이 느려짐.
- 해결책: 항상 try‑with‑resources 또는 명시적인
close()호출을 사용해 네이티브 버퍼를 해제하십시오.
try (Annotator annotator = new Annotator("large.pdf")) {
// process
}
좌표계 혼동
- 문제: 주석이 화면 밖에 표시됨.
- 해결책: GroupDocs는 왼쪽 상단을 원점으로 사용한다는 점을 기억하십시오. 동적 값을 적용하기 전에 (50, 50, 100, 50)과 같은 알려진 좌표로 테스트하십시오.
AreaAnnotation test = new AreaAnnotation();
test.setRectangle(new Rectangle(50, 50, 100, 50));
annotator.add(test);
실제 사용 사례 및 응용 프로그램
문서 검토 워크플로
법무 팀은 종종 누가 어떤 조항에 댓글을 달았는지 추적해야 합니다. GroupDocs.Annotation을 사용하면 다음을 수행할 수 있습니다:
- 검토자마다 고유한 색상을 할당합니다.
- 주석 메타데이터에 타임스탬프와 사용자 ID를 저장합니다.
- 감사 추적을 보존하면서 클라이언트 배포용으로 주석이 달린 PDF를 내보냅니다.
area.setCreator("lawyer@example.com");
area.setCreatedOn(LocalDateTime.now());
교육 콘텐츠 제작
E‑learning 플랫폼은 핵심 개념을 강조하고 퀴즈를 삽입하거나 학습 PDF에 직접 설명 노트를 추가하기 위해 주석을 사용합니다. 이는 일반 PDF에 비해 학습 유지율을 최대 35 % 향상시킵니다(내부 연구).
품질 보증 문서
제조업체는 기술 도면에 공차, 수정 및 안전 경고를 표시하기 위해 주석을 달습니다. 표준화된 마크업은 생산 라인 전체에서 재작업을 약 22 % 감소시킵니다.
성능 최적화 팁
대용량 문서를 효율적으로 처리하기
전체 파일을 로드하지 않고 페이지를 스트리밍하면 일반적인 4코어 서버에서 200페이지 PDF를 2초 미만으로 처리할 수 있습니다.
Annotator annotator = new Annotator(new FileInputStream("big.pdf"));
메모리 사용량 모니터링
대용량 파일에 주석을 달면서 힙 사용량을 확인하려면 Java 내장 모니터링 도구(JVisualVM, JConsole)를 활성화하십시오. 힙 사용량을 최대 할당량의 70 % 이하로 유지하는 것을 목표로 합니다.
동시 처리 고려 사항
GroupDocs.Annotation 인스턴스는 스레드 안전하지 않습니다. 병렬 작업에서는 스레드당 별도의 Annotator를 생성하거나 스레드 로컬 풀을 사용하십시오.
ExecutorService executor = Executors.newFixedThreadPool(4);
for (String path : pdfPaths) {
executor.submit(() -> {
try (Annotator a = new Annotator(path)) {
// annotate
a.save(path.replace(".pdf", "_annotated.pdf"));
}
});
}
고급 주석 기법
하나의 문서에 여러 주석 유형
하이라이트, 텍스트 노트 및 워터마크를 한 번에 혼합할 수 있습니다:
String INPUT_PDF = "YOUR_DOCUMENT_DIRECTORY/input.pdf";
String outputPath = "YOUR_OUTPUT_DIRECTORY/output_annotated.pdf";
// Initialize Annotator with the path to your document
final Annotator annotator = new Annotator(INPUT_PDF);
콘텐츠 기반 동적 주석
GroupDocs.Annotation을 Apache PDFBox 또는 Tika와 결합하여 키워드를 자동으로 감지하고 상황에 맞는 노트를 추가하십시오.
// pseudo‑code: detect the word "confidential"
if (pageText.contains("confidential")) {
WatermarkAnnotation wm = new WatermarkAnnotation();
wm.setText("CONFIDENTIAL");
annotator.add(wm);
}
문제 해결 가이드
일반 오류 메시지 및 해결책
- “Invalid license” – 라이선스 파일이 클래스패스에 있고 배포 유형과 일치하는지 확인하십시오.
- “Unsupported file format” – PDF가 손상되지 않았고, 비밀번호가 걸려 있지 않으며, 0바이트가 아닌지 확인하십시오.
- Performance slowdown – 스트리밍을 사용하고
Annotator객체를 즉시 해제하며 배치 처리를 고려하십시오.
디버깅 팁
로깅 활성화
System.setProperty("log4j.configurationFile", "log4j2.xml");
입력 검증
Objects.requireNonNull(filePath, "File path cannot be null");
자주 묻는 질문
Q: 단일 PDF에 여러 주석을 효율적으로 추가하려면 어떻게 해야 하나요?
A: annotator.add(annotation)을 각 주석마다 호출하고, 마지막에 한 번 save()를 호출하십시오. GroupDocs는 변경 사항을 배치 처리하여 한 번에 기록합니다.
annotator.add(area1);
annotator.add(highlight2);
annotator.save("combined.pdf");
Q: PDF 외에 GroupDocs.Annotation이 지원하는 파일 형식은 무엇인가요?
A: DOC, DOCX, PPT, PPTX, XLS, XLSX, JPEG, PNG, TIFF 등을 포함해 50개 이상의 형식을 지원합니다. 전체 목록은 GroupDocs.Annotation 문서에서 확인하십시오.
Q: 비밀번호가 보호된 PDF를 어떻게 처리하나요?
Annotator annotator = new Annotator("secure.pdf", "password123");
Q: PDF에서 기존 주석을 검색하고 수정할 수 있나요?
List<AnnotationBase> existing = annotator.getAll();
for (AnnotationBase a : existing) {
if (a instanceof TextAnnotation) {
((TextAnnotation) a).setComment("Updated comment");
}
}
annotator.save("updated.pdf");
Q: 대용량 PDF를 처리할 때 성능에 어떤 영향을 미치나요?
A: 50 MB보다 큰 파일은 페이지별로 스트리밍해야 합니다. 페이지 배치를 처리한 후 각 Annotator를 해제하면 메모리 사용량이 150 MB 이하로 유지됩니다.
Q: 웹 애플리케이션에서 동시 문서 처리를 어떻게 관리하나요?
// each request gets its own Annotator instance
public void processPdf(String path) {
try (Annotator a = new Annotator(path)) {
// annotate
a.save(path);
}
}
Q: 주석 위치 문제를 디버깅하는 가장 좋은 방법은 무엇인가요?
A: 알려진 사각형(예: (50, 50, 100, 50))으로 시작하고 시각적 결과를 확인하십시오. 좌표를 점진적으로 조정하고 PDF 페이지 크기(보통 612 × 792 포인트)를 참고하십시오.
Q: GroupDocs.Annotation을 Spring Boot와 어떻게 통합하나요?
@Service
public class PdfAnnotationService {
public void addComment(String filePath, String comment) throws IOException {
try (Annotator annotator = new Annotator(filePath)) {
AreaAnnotation a = new AreaAnnotation();
a.setRectangle(new Rectangle(100, 200, 250, 80));
a.setComment(comment);
annotator.add(a);
annotator.save(filePath);
}
}
}
추가 FAQ
Q: 주석이 달린 PDF를 다른 형식으로 내보낼 수 있나요?
A: 예, 주석이 포함된 PDF를 모든 마크업을 유지하면서 DOCX, PPTX 또는 이미지 형식으로 변환할 수 있습니다.
Q: 라이브러리가 지원하는 모든 주석 유형을 나열하는 방법이 있나요?
A: 지원되는 모든 enum 배열을 얻으려면 AnnotationType.values()를 사용하십시오.
Q: 워터마크 주석의 외관을 어떻게 사용자 정의할 수 있나요?
A: WatermarkAnnotation을 추가하기 전에 setOpacity, setRotation, setBackgroundColor와 같은 속성을 설정하십시오.
Q: 라이브러리가 데이터베이스에서 프로그래밍 방식으로 댓글을 추가하는 것을 지원하나요?
A: 물론입니다. 어떤 소스에서든 댓글 데이터를 읽어 AreaAnnotation(또는 TextAnnotation)에 텍스트를 채우고 문서에 추가하십시오.
Q: 배치 처리 중 메모리 누수가 발생하면 어떻게 해야 하나요?
A: 모든 Annotator를 닫고(try‑with‑resources 사용), JVM 힙을 모니터링하며, 큰 배치를 작은 그룹으로 나누십시오.
추가 리소스
- GroupDocs.Annotation 문서
- API Reference Guide
- Download Latest Version
- Purchase License
- Free Trial Access
- Temporary License
- Support Forum
마지막 업데이트: 2026-10-16
테스트 환경: GroupDocs.Annotation 25.2 for Java
작성자: GroupDocs
// From file path (most common)
Annotator annotatorFromPath = new Annotator("path/to/document.pdf");
// From InputStream (useful for uploaded files)
FileInputStream inputStream = new FileInputStream("document.pdf");
Annotator annotatorFromStream = new Annotator(inputStream);
// Don't forget to close streams when done!
inputStream.close();
import com.groupdocs.annotation.models.Rectangle;
import com.groupdocs.annotation.models.annotationmodels.AreaAnnotation;
// Create the annotation
AreaAnnotation area = new AreaAnnotation();
// Position and size: x, y, width, height
area.setBox(new Rectangle(100, 100, 100, 100));
// Background color in ARGB format (65535 = yellow with transparency)
area.setBackgroundColor(65535);
// Add the annotation to your document
annotator.add(area);
// Create a semi‑transparent highlight
AreaAnnotation highlight = new AreaAnnotation();
highlight.setBox(new Rectangle(50, 200, 200, 25));
highlight.setBackgroundColor(0x80FFFF00); // Semi‑transparent yellow
highlight.setMessage("Important clause - review carefully");
// Add a comment annotation with custom styling
AreaAnnotation comment = new AreaAnnotation();
comment.setBox(new Rectangle(300, 150, 150, 75));
comment.setBackgroundColor(0x80FF0000); // Semi‑transparent red
comment.setMessage("Needs revision - see discussion in email");
comment.setCreatedOn(new Date());
comment.setUser("John Reviewer");
// Save the annotated document
annotator.save(outputPath);
// Always dispose of resources (critical for memory management)
annotator.dispose();
public void annotateDocument(String inputPath, String outputPath) {
try (Annotator annotator = new Annotator(inputPath)) {
// Your annotation code here
AreaAnnotation area = new AreaAnnotation();
area.setBox(new Rectangle(100, 100, 100, 100));
area.setBackgroundColor(65535);
annotator.add(area);
annotator.save(outputPath);
System.out.println("Document successfully annotated and saved to: " + outputPath);
} catch (Exception e) {
System.err.println("Annotation failed: " + e.getMessage());
throw new RuntimeException("Failed to annotate document", e);
}
}
public boolean validateInputFile(String filePath) {
File file = new File(filePath);
if (!file.exists()) {
System.err.println("File does not exist: " + filePath);
return false;
}
if (!file.canRead()) {
System.err.println("Cannot read file: " + filePath);
return false;
}
return true;
}
// Good practice - automatic resource management
try (Annotator annotator = new Annotator(inputPath)) {
// Annotation code here
} // Automatically disposed
// If manual disposal is needed
Annotator annotator = null;
try {
annotator = new Annotator(inputPath);
// Annotation code here
} finally {
if (annotator != null) {
annotator.dispose();
}
}
// Start with simple, visible coordinates for testing
Rectangle testPosition = new Rectangle(50, 50, 100, 50);
// Gradually adjust based on your PDF dimensions
// Most PDFs are 612x792 points (8.5"x11" at 72 DPI)
public void addReviewAnnotation(Annotator annotator, String reviewerName,
String comment, Rectangle position, Color highlightColor) {
AreaAnnotation review = new AreaAnnotation();
review.setBox(position);
review.setBackgroundColor(highlightColor.getRGB());
review.setMessage(comment);
review.setUser(reviewerName);
review.setCreatedOn(new Date());
annotator.add(review);
}
public void processDocumentBatch(List<String> documentPaths) {
for (String path : documentPaths) {
try (Annotator annotator = new Annotator(path)) {
// Process each document independently
// This prevents memory accumulation
processAnnotations(annotator);
}
// Optional: Add small delay for very large batches
// Thread.sleep(100);
}
}
Runtime runtime = Runtime.getRuntime();
long memoryBefore = runtime.totalMemory() - runtime.freeMemory();
// Process documents...
long memoryAfter = runtime.totalMemory() - runtime.freeMemory();
System.out.println("Memory used: " + (memoryAfter - memoryBefore) + " bytes");
public class ConcurrentAnnotationProcessor {
public void processDocumentsConcurrently(List<String> documents) {
documents.parallelStream().forEach(docPath -> {
try (Annotator annotator = new Annotator(docPath)) {
// Each thread gets its own Annotator instance
processAnnotations(annotator);
}
});
}
}
public void createComprehensiveAnnotation(Annotator annotator) {
// Highlight important text
AreaAnnotation highlight = new AreaAnnotation();
highlight.setBox(new Rectangle(100, 100, 200, 30));
highlight.setBackgroundColor(0x80FFFF00);
// Add explanatory note
AreaAnnotation note = new AreaAnnotation();
note.setBox(new Rectangle(320, 95, 150, 40));
note.setBackgroundColor(0x80ADD8E6);
note.setMessage("See reference document #123");
annotator.add(highlight);
annotator.add(note);
}
// Add to your application properties or logging configuration
java.util.logging.Logger.getLogger("com.groupdocs").setLevel(Level.FINE);
public boolean validateAnnotationParameters(Rectangle box, int color) {
if (box.getWidth() <= 0 || box.getHeight() <= 0) {
System.err.println("Invalid annotation dimensions");
return false;
}
if (box.getX() < 0 || box.getY() < 0) {
System.err.println("Annotation position cannot be negative");
return false;
}
return true;
}
try (Annotator annotator = new Annotator("document.pdf")) {
annotator.add(annotation1);
annotator.add(annotation2);
annotator.add(annotation3);
annotator.save("output.pdf"); // All annotations applied at once
}
LoadOptions loadOptions = new LoadOptions();
loadOptions.setPassword("your-password");
Annotator annotator = new Annotator("protected.pdf", loadOptions);
try (Annotator annotator = new Annotator("annotated.pdf")) {
List<AnnotationInfo> annotations = annotator.get(AnnotationType.Area);
for (AnnotationInfo annotation : annotations) {
// Modify properties as needed
annotation.setMessage("Updated comment");
}
annotator.update(annotations);
annotator.save("updated.pdf");
}
@Service
public class AnnotationService {
public CompletableFuture<String> annotateAsync(String inputPath) {
return CompletableFuture.supplyAsync(() -> {
try (Annotator annotator = new Annotator(inputPath)) {
// Process annotations
return processDocument(annotator);
}
});
}
}
@Service
public class DocumentAnnotationService {
public void annotateDocument(MultipartFile file, List<AnnotationRequest> requests) {
try (InputStream inputStream = file.getInputStream();
Annotator annotator = new Annotator(inputStream)) {
// Process annotation requests
requests.forEach(request -> addAnnotation(annotator, request));
annotator.save("output.pdf");
}
}
}