Anotaciones de marca de agua usando Java
Contents
[
Hide
]
Agregar una anotación de marca de agua
- Abra el PDF de entrada y defina el rectángulo donde se colocará la anotación de marca de agua.
- Cree el
WatermarkAnnotation, añádelo a la página y configure el estado del texto de la marca de agua y la opacidad. - Aplique las líneas de texto de la marca de agua y guarde el PDF modificado.
public static void watermarkAdd(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
WatermarkAnnotation watermarkAnnotation = new WatermarkAnnotation(
document.getPages().get_Item(1), new Rectangle(100, 0, 400, 100, true));
document.getPages().get_Item(1).getAnnotations().add(watermarkAnnotation);
TextState textState = new TextState();
textState.setForegroundColor(Color.getBlue());
textState.setFontSize(25);
textState.setFont(FontRepository.findFont("Arial"));
watermarkAnnotation.setOpacity(0.5);
watermarkAnnotation.setTextAndState(new String[]{"HELLO", "Line 1", "Line 2"}, textState);
document.save(outputFile.toString());
}
}