Anotaciones interactivas usando Java
Contents
[
Hide
]
Agregar una anotación de enlace
- Cargue el documento PDF de origen y busque en la primera página el texto objetivo.
- Utilice el rectángulo de texto coincidente para crear un
LinkAnnotationy asignar la URI de destino. - Añada la anotación a la página y guarde el PDF actualizado.
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());
}
}