From 148a7f11b0ead8539cae824f02dda19a703f4d0b Mon Sep 17 00:00:00 2001 From: zjh <1084500556@qq.com> Date: 星期六, 07 十二月 2024 16:54:02 +0800 Subject: [PATCH] zjh20241207 --- ltkj-admin/src/main/java/com/ltkj/web/config/pdfutils/PdfUtils.java | 22 ++++++++++++++++++---- 1 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ltkj-admin/src/main/java/com/ltkj/web/config/pdfutils/PdfUtils.java b/ltkj-admin/src/main/java/com/ltkj/web/config/pdfutils/PdfUtils.java index df49606..3631f58 100644 --- a/ltkj-admin/src/main/java/com/ltkj/web/config/pdfutils/PdfUtils.java +++ b/ltkj-admin/src/main/java/com/ltkj/web/config/pdfutils/PdfUtils.java @@ -1,5 +1,6 @@ package com.ltkj.web.config.pdfutils; +import cn.hutool.core.io.FileUtil; import com.itextpdf.text.*; import com.itextpdf.text.pdf.BaseFont; import com.itextpdf.text.pdf.PdfContentByte; @@ -8,8 +9,10 @@ import com.ltkj.hosp.domain.TjPdfVO; import javax.servlet.http.HttpServletResponse; +import java.io.File; import java.io.IOException; import java.net.URLEncoder; +import java.nio.file.Files; import java.util.List; import static com.itextpdf.text.Rectangle.NO_BORDER; @@ -24,7 +27,7 @@ /** * 瀛椾綋瀛樻斁鐨勮窡璺緞锛岄粯璁や负'C:\Windows\Fonts\' */ - private static final String FONT_PATH = "C:\\Windows\\Fonts\\"; + private static final String FONT_PATH = System.getProperty("user.dir") + File.separator + "ltkj-admin"+File.separator+"src"+File.separator+"main"+File.separator+"resources"+File.separator+"Font"+File.separator; // private static final String FONT_PATH = "/Users/chacca/寮�鍙戠浉鍏�/浠g爜/ltkj_peis/ltkj-admin/src/main/resources/Font/"; /** @@ -39,7 +42,7 @@ * @throws DocumentException * @throws IOException */ - private static BaseFont createBaseFont(String fontName) throws DocumentException, IOException { + public static BaseFont createBaseFont(String fontName) throws DocumentException, IOException { // 榛樿涓哄畫浣� if (fontName == null) { fontName = "simsun.ttc"; @@ -51,6 +54,17 @@ } String font = FONT_PATH + fontName; return BaseFont.createFont(font, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); + } + + public static void main(String[] args) { + try { + BaseFont simsun = createBaseFont(null); + System.out.println("simsun = " + simsun); + } catch (DocumentException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } } /** @@ -152,7 +166,7 @@ */ public static PdfPTable setTable(Font headFont, Font textFont, String[] title, List<TjPdfVO> list) { //鍥涘垪 - PdfPTable table = createTable(new float[]{120, 120, 120, 120}); + PdfPTable table = createTable(new float[]{120, 120, 120}); //鐢绘爣棰� for (String head : title) { table.addCell(createCell(head, headFont)); @@ -162,7 +176,7 @@ table.addCell(createCell(tjPdfVO.getProName(), textFont)); table.addCell(createCell(tjPdfVO.getProResult(), textFont)); table.addCell(createCell(tjPdfVO.getCompany(), textFont)); - table.addCell(createCell(tjPdfVO.getStandardValue(), textFont)); +// table.addCell(createCell(tjPdfVO.getStandardValue(), textFont)); } return table; } -- Gitblit v1.8.0