Annotations interactives utilisant Java
Contents
[
Hide
]
Ajouter une annotation de lien
-
Chargez le document PDF source et recherchez le texte cible dans la première page.
-
Utilisez le rectangle de texte correspondant pour créer un objet
LinkAnnotationet attribuer l’URI de destination. -
Ajoutez l’annotation à la page et enregistrez le PDF mis à jour.
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());
}
}