Java를 사용한 워터마크 주석
Contents
[
Hide
]
워터마크 주석 추가
- 입력 PDF를 열고 워터마크 주석이 배치될 직사각형을 정의하세요.
WatermarkAnnotation을 생성하여 페이지에 추가하고 워터마크 텍스트 상태와 불투명도를 구성하세요.- 워터마크 텍스트 줄을 적용하고 수정된 PDF를 저장하세요.
public static void watermarkAdd(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
WatermarkAnnotation watermarkAnnotation = new WatermarkAnnotation(
document.getPages().get_Item(1), new Rectangle(100, 0, 400, 100, true));
document.getPages().get_Item(1).getAnnotations().add(watermarkAnnotation);
TextState textState = new TextState();
textState.setForegroundColor(Color.getBlue());
textState.setFontSize(25);
textState.setFont(FontRepository.findFont("Arial"));
watermarkAnnotation.setOpacity(0.5);
watermarkAnnotation.setTextAndState(new String[]{"HELLO", "Line 1", "Line 2"}, textState);
document.save(outputFile.toString());
}
}