feat: 水印支持页边距控制

This commit is contained in:
2024-01-11 15:46:25 +08:00
parent ba53565a0e
commit 7366808e9d
7 changed files with 25 additions and 171 deletions
@@ -57,6 +57,13 @@ public class SysWaterMarkUtil {
private int degree;
@Value("${watermark.margin.left}")
private float marginLeft;
@Value("${watermark.margin.top}")
private float marginTop;
public List<String> getWaterMarkConfig() {
LoginUser loginUser = UserUtils.getLoginUser();
if (loginUser == null) {
@@ -104,8 +111,8 @@ public class SysWaterMarkUtil {
// 计算两行文本的总高度
float totalTextHeight = (dynamicFontSize + lineSpacing) * (watermarkText.size() - 1);
for (float xPosition = pageSize.getLowerLeftX(); xPosition <= pageWidth; xPosition += xStep) {
for (float yPosition = pageSize.getLowerLeftY(); yPosition <= pageHeight; yPosition += yStep) {
for (float xPosition = pageSize.getLowerLeftX() + marginLeft; xPosition <= pageWidth - marginLeft; xPosition += xStep) {
for (float yPosition = pageSize.getLowerLeftY() + marginTop; yPosition <= pageHeight - marginTop; yPosition += yStep) {
try (PDPageContentStream contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND, true, true)) {
contentStream.setGraphicsStateParameters(graphicsState);
contentStream.setNonStrokingColor(color);