feat: 水印支持页边距控制
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user