Anotaciones basadas en texto usando Java

Agregar una anotación de texto

  1. Abra el PDF de entrada y seleccione la página donde se debe colocar la anotación de texto.
  2. Cree el TextAnnotation, defina su rectángulo y establezca su título, asunto, banderas y color.
  3. 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

  1. Cargue el PDF de origen y seleccione la página objetivo y el rectángulo para la nota de texto libre.
  2. Cree el FreeTextAnnotation", inicializa su apariencia predeterminada y establezca el título y el color.".
  3. 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());
    }
}