Anotaciones basadas en texto usando Java
Contents
[
Hide
]
Agregar una anotación de texto
- Abra el PDF de entrada y seleccione la página donde se debe colocar la anotación de texto.
- Cree el
TextAnnotation, defina su rectángulo y establezca su título, asunto, banderas y color. - Añada la anotación a la página y guarde el documento actualizado.
public static void textAnnotationAdd(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
TextAnnotation textAnnotation = new TextAnnotation(
document.getPages().get_Item(1), new Rectangle(299.988, 613.664, 428.708, 680.769, true));
textAnnotation.setTitle("Aspose User");
textAnnotation.setSubject("Inserted text 1");
textAnnotation.setFlags(AnnotationFlags.Print);
textAnnotation.setColor(Color.getBlue());
document.getPages().get_Item(1).getAnnotations().add(textAnnotation, false);
document.save(outputFile.toString());
}
}
Agregar una anotación de texto libre
- Cargue el PDF de origen y seleccione la página objetivo y el rectángulo para la nota de texto libre.
- Cree el
FreeTextAnnotation", inicializa su apariencia predeterminada y establezca el título y el color.". - Agregue la anotación a la página y guarde el resultado.
public static void freeTextAnnotationAdd(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
FreeTextAnnotation freeTextAnnotation = new FreeTextAnnotation(
document.getPages().get_Item(1),
new Rectangle(299, 713, 308, 720, true),
new DefaultAppearance());
freeTextAnnotation.setTitle("Aspose User");
freeTextAnnotation.setColor(Color.getLightGreen());
document.getPages().get_Item(1).getAnnotations().add(freeTextAnnotation);
document.save(outputFile.toString());
}
}