修改字体代码

This commit is contained in:
xzh
2025-03-26 01:09:14 +08:00
parent 8d586da1ba
commit 8a772cae16
4 changed files with 16 additions and 2 deletions

View File

@@ -245,3 +245,7 @@ justauth:
client-id: 10**********6
client-secret: 1f7d08**********5b7**********29e
redirect-uri: ${justauth.address}/social-callback?source=gitlab
# 字体文件路径
ttfFile:
path: E:\giftBook\MicrosoftYaHei.ttf

View File

@@ -247,3 +247,7 @@ justauth:
client-id: 10**********6
client-secret: 1f7d08**********5b7**********29e
redirect-uri: ${justauth.address}/social-callback?source=gitlab
# 字体文件路径
ttfFile:
path: /usr/local/project/giftBook/jar/fonts/MicrosoftYaHei.ttf

View File

@@ -39,9 +39,11 @@ import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.ConstraintViolationException;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -62,6 +64,10 @@ public class TGiftBookDetailsServiceImpl implements ITGiftBookDetailsService {
private final ITGiftBookService giftBookService;
@Value("ttfFile.path")
private String ttfPath;
/**
* 查询礼薄详情
*
@@ -237,8 +243,8 @@ public class TGiftBookDetailsServiceImpl implements ITGiftBookDetailsService {
Document document = new Document(pdfDoc, PageSize.A4, false);
// 设置字体
ClassPathResource fontResource = new ClassPathResource("/fonts/MicrosoftYaHei.ttf");
PdfFont font = PdfFontFactory.createFont(fontResource.getFile().getAbsolutePath(), PdfEncodings.IDENTITY_H);
File file = new File(ttfPath);
PdfFont font = PdfFontFactory.createFont(file.getAbsolutePath(), PdfEncodings.IDENTITY_H);
document.setFont(font);
pdfDoc.addNewPage();