From 593bf59f8b86070496b58fee7a4506527752f8a4 Mon Sep 17 00:00:00 2001 From: thisisrenan Date: Tue, 12 Nov 2024 17:03:44 -0300 Subject: [PATCH] Increase watermark coverage to fill page (#2049) --- .../SPDF/controller/api/security/WatermarkController.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java b/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java index de7efd713c6..9f779d881b0 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java @@ -190,8 +190,14 @@ private void addTextWatermark( int watermarkRows = (int) (pageHeight / watermarkHeight + 1); int watermarkCols = (int) (pageWidth / watermarkWidth + 1); + // Calculating the effective line length according to the angle used + float effectiveHeight = watermarkHeight / (float) Math.cos(Math.toRadians(rotation)); + int watermarkRowsRotation = (int) (pageHeight / effectiveHeight + 1); + // Add the text watermark - for (int i = 0; i < watermarkRows; i++) { + /* In the 'for' loop, is do (watermarkRowsRotation - watermarkRows) so that the watermark starts at the bottom of the page. + This compensate for the rotation by adjusting the starting point for inserting the watermark. */ + for (int i = (watermarkRowsRotation - watermarkRows); i < watermarkRows; i++) { for (int j = 0; j < watermarkCols; j++) { contentStream.beginText(); contentStream.setTextMatrix(