Hello
Using the artifact object in my code makes it go to the first sheet with the opacity I want but after the first sheet the opacity returns to 1. Example:
watermark.pdf (865.2 KB)
This is the code I am working with:
public static void main(String[] args) throws Exception {// Main function to add watermark to PDF in Java
// Initialize License Instance
License license = new License();
// Call setLicense method to set license
license.setLicense(“src/Aspose.Pdf.Java.lic”);
long startTime = System.currentTimeMillis();
// Load PDF document
Document doc = new Document("src/marcaDeAgua/AyDSI_I_-_Clase_1.pdf");
// Create formatted text
FormattedText formattedText = new FormattedText("Restringido", java.awt.Color.BLUE, FontStyle.Courier,
EncodingType.Identity_h, true, 20);
//Crea el Watermark
WatermarkArtifact artifact = new WatermarkArtifact();
artifact.setText(formattedText);
artifact.setBackground(false);
//Setea la marca de agua en la hoja por primera vez para recuperar despues sus medidas
doc.getPages().get_Item(1).getArtifacts().add(artifact);
//Ancho y altura del artefacto
double anchoWt = artifact.getRectangle().getWidth();
double alturaWt = artifact.getRectangle().getHeight();
// For de la hoja a trabajar
for (int i = 1; i <= doc.getPages().size(); i++) {
Rectangle mediabox = doc.getPages().get_Item(i).getMediaBox();
// For de la altura para el watermark
for (double h = 0; h <= mediabox.getHeight(); h = h + (alturaWt + 10)) {
// For para el ancho para el watermark
for (double w = 0; w <= mediabox.getWidth(); w = w + (anchoWt+8)) {
// Pointer de la ubicacion del watermark
Point point = new Point(w, h);
artifact.setPosition(point);
artifact.setOpacity(0.5);
//Setea la marca de agua en la hoja
doc.getPages().get_Item(i).getArtifacts().add(artifact);
}
}
}
// Save watermarked PDF document
doc.save("src/marcaDeAgua/watermark.pdf");
long tarda = System.currentTimeMillis() - startTime;
System.out.println(tarda);
System.out.println("Done");
doc.close();
}