Anotações interativas usando Java
Contents
[
Hide
]
Adicionar uma anotação de link
- Carregue o documento PDF de origem e pesquise a primeira página pelo texto alvo.
- Use o retângulo de texto correspondente para criar um
LinkAnnotatione atribua o URI de destino. - Adicione a anotação à página e salve o PDF atualizado.
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());
}
}