refactor: 更新 pdf 模板

11111
winter 10 months ago
parent a00e0eaf2e
commit bbef6070fd

@ -1,9 +1,11 @@
package cn.teammodel.utils; package cn.teammodel.utils;
import com.itextpdf.text.DocumentException; import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image; import com.itextpdf.text.Image;
import com.itextpdf.text.Rectangle; import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.AcroFields; import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfContentByte; import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfStamper; import com.itextpdf.text.pdf.PdfStamper;
@ -16,8 +18,13 @@ import java.util.Map;
*/ */
public class PdfUtil { public class PdfUtil {
public static void fillPdfForm(PdfStamper stamper, Map<String, String> data) throws IOException, DocumentException { public static void fillPdfForm(PdfStamper stamper, Map<String, String> data) throws IOException, DocumentException {
BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Font boldFont = new Font(baseFont, 16, Font.BOLD);
AcroFields fields = stamper.getAcroFields(); AcroFields fields = stamper.getAcroFields();
for (Map.Entry<String, String> entry : data.entrySet()) { for (Map.Entry<String, String> entry : data.entrySet()) {
fields.setFieldProperty(entry.getKey(), "textsize", boldFont.getSize(), null);
fields.setFieldProperty(entry.getKey(), "textfont", baseFont, null); // 设置字体为加粗
fields.setField(entry.getKey(), entry.getValue()); fields.setField(entry.getKey(), entry.getValue());
} }
} }

Loading…
Cancel
Save