We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Increased opacity of watermark after page 1

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();
}

@FedericoK

Can you please share the respective input document as well? We will test the scenario in our environment and address it accordingly.

of course, here is the input doc:
AyDSI_I_-_Clase_1.pdf (206.6 KB)

but you can do it with any pdf and the resut will be the same.

@FedericoK

We were able to notice the issue in our environment while testing the case with 22.12 version of the API. Hence, it has been logged as PDFJAVA-42373 in our issue tracking system. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

Thank you, I’ll wait for the reponse.