feat: 将水印的相关设置提出到配置文件
This commit is contained in:
+18
-2
@@ -11,6 +11,7 @@ import org.apache.pdfbox.pdmodel.font.PDType0Font;
|
||||
import org.apache.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState;
|
||||
import org.apache.pdfbox.pdmodel.graphics.state.RenderingMode;
|
||||
import org.apache.pdfbox.util.Matrix;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -31,6 +32,21 @@ import java.time.format.DateTimeFormatter;
|
||||
@Component
|
||||
public class SysWaterMarkUtil {
|
||||
|
||||
@Value("${watermark.font-size}")
|
||||
private float fontSize;
|
||||
|
||||
@Value("${watermark.color.r}")
|
||||
private int r;
|
||||
|
||||
@Value("${watermark.color.g}")
|
||||
private int g;
|
||||
|
||||
@Value("${watermark.color.b}")
|
||||
private int b;
|
||||
|
||||
@Value("${watermark.color.a}")
|
||||
private int a;
|
||||
|
||||
public String getWaterMarkConfig() {
|
||||
LoginUser loginUser = UserUtils.getLoginUser();
|
||||
if (loginUser == null) {
|
||||
@@ -46,8 +62,8 @@ public class SysWaterMarkUtil {
|
||||
// 设置水印字体、字体大小、颜色和透明度
|
||||
ClassPathResource fontResource = new ClassPathResource("fonts/SourceHanSerif-VF.ttf");
|
||||
PDType0Font font = PDType0Font.load(document, fontResource.getInputStream());
|
||||
float fontSize = 13.0f;
|
||||
Color color = new Color(180, 180, 180, 1);
|
||||
float fontSize = this.fontSize;
|
||||
Color color = new Color(r, g, b, a);
|
||||
PDExtendedGraphicsState graphicsState = new PDExtendedGraphicsState();
|
||||
graphicsState.setNonStrokingAlphaConstant(0.4f);
|
||||
graphicsState.setStrokingAlphaConstant(0.4f);
|
||||
|
||||
Reference in New Issue
Block a user