Java를 사용한 대화형 주석
Contents
[
Hide
]
링크 주석 추가
- 원본 PDF 문서를 로드하고 첫 번째 페이지에서 대상 텍스트를 검색하세요.
- 일치하는 텍스트 직사각형을 사용하여
LinkAnnotation을 만들고 대상 URI를 할당하세요. - 페이지에 주석을 추가하고 업데이트된 PDF를 저장하세요.
public static void linkAdd(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("file");
document.getPages().get_Item(1).accept(textFragmentAbsorber);
TextFragment phoneNumberFragment = textFragmentAbsorber.getTextFragments().get_Item(1);
LinkAnnotation linkAnnotation = new LinkAnnotation(
document.getPages().get_Item(1), phoneNumberFragment.getRectangle());
linkAnnotation.setAction(new GoToURIAction("www.aspose.com"));
document.getPages().get_Item(1).getAnnotations().add(linkAnnotation);
document.save(outputFile.toString());
}
}