feat: support '\n' literal in add watermark
This commit is contained in:
parent
53afb865c5
commit
2d37c707e2
1 changed files with 15 additions and 3 deletions
|
@ -155,9 +155,16 @@ public class WatermarkController {
|
||||||
contentStream.setFont(font, fontSize);
|
contentStream.setFont(font, fontSize);
|
||||||
contentStream.setNonStrokingColor(Color.LIGHT_GRAY);
|
contentStream.setNonStrokingColor(Color.LIGHT_GRAY);
|
||||||
|
|
||||||
|
String[] textLines = watermarkText.split("\\\\n");
|
||||||
|
float maxLineWidth = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < textLines.length; ++i) {
|
||||||
|
maxLineWidth = Math.max(maxLineWidth, font.getStringWidth(textLines[i]));
|
||||||
|
}
|
||||||
|
|
||||||
// Set size and location of text watermark
|
// Set size and location of text watermark
|
||||||
float watermarkWidth = widthSpacer + font.getStringWidth(watermarkText) * fontSize / 1000;
|
float watermarkWidth = widthSpacer + maxLineWidth * fontSize / 1000;
|
||||||
float watermarkHeight = heightSpacer + fontSize;
|
float watermarkHeight = heightSpacer + fontSize * textLines.length;
|
||||||
float pageWidth = page.getMediaBox().getWidth();
|
float pageWidth = page.getMediaBox().getWidth();
|
||||||
float pageHeight = page.getMediaBox().getHeight();
|
float pageHeight = page.getMediaBox().getHeight();
|
||||||
int watermarkRows = (int) (pageHeight / watermarkHeight + 1);
|
int watermarkRows = (int) (pageHeight / watermarkHeight + 1);
|
||||||
|
@ -172,7 +179,12 @@ public class WatermarkController {
|
||||||
(float) Math.toRadians(rotation),
|
(float) Math.toRadians(rotation),
|
||||||
j * watermarkWidth,
|
j * watermarkWidth,
|
||||||
i * watermarkHeight));
|
i * watermarkHeight));
|
||||||
contentStream.showText(watermarkText);
|
|
||||||
|
for (int k = 0; k < textLines.length; ++k) {
|
||||||
|
contentStream.showText(textLines[k]);
|
||||||
|
contentStream.newLineAtOffset(0, -fontSize);
|
||||||
|
}
|
||||||
|
|
||||||
contentStream.endText();
|
contentStream.endText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue