Java를 사용한 보안 주석
Contents
[
Hide
]
교정할 텍스트 표시
- PDF를 로드하고 수정해야 할 텍스트를 모든 페이지에서 검색하세요.
- 일치하는 각 텍스트 조각에 대해
RedactionAnnotation을 만들고 모양을 구성하세요. - 해당 페이지에 교정 주석을 추가하고 문서를 저장하세요.
public static void markTextRedaction(Path inputFile, Path outputFile, String searchTerm) {
try (Document document = new Document(inputFile.toString())) {
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(searchTerm);
TextSearchOptions textSearchOptions = new TextSearchOptions(true);
textFragmentAbsorber.setTextSearchOptions(textSearchOptions);
document.getPages().accept(textFragmentAbsorber);
for (TextFragment textFragment : textFragmentAbsorber.getTextFragments()) {
Page page = textFragment.getPage();
Rectangle annotationRectangle = textFragment.getRectangle();
RedactionAnnotation annotation = new RedactionAnnotation(page, annotationRectangle);
annotation.setFillColor(Color.getGray());
annotation.setBorderColor(Color.getRed());
annotation.setColor(Color.getWhite());
annotation.setOverlayText("REDACTED");
annotation.setTextAlignment(HorizontalAlignment.Center);
annotation.setRepeat(true);
page.getAnnotations().add(annotation, true);
}
document.save(outputFile.toString());
}
}