|
@@ -44,14 +44,13 @@ public class PdfUtils { |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
File directory = new File(""); |
|
|
File directory = new File(""); |
|
|
//pdf输出路径 |
|
|
|
|
|
|
|
|
//临时文件输出路径 |
|
|
String filePath = directory.getAbsolutePath() + File.separator + "fileout"; |
|
|
String filePath = directory.getAbsolutePath() + File.separator + "fileout"; |
|
|
String templatePath = ResourceUtil.getResource("").getPath(); |
|
|
|
|
|
|
|
|
//字体格式 |
|
|
|
|
|
String fontPath = ResourceUtil.getResource("template/simsun.ttc").getPath(); |
|
|
if(!new File(filePath).exists()){ |
|
|
if(!new File(filePath).exists()){ |
|
|
new File(filePath).mkdir(); |
|
|
new File(filePath).mkdir(); |
|
|
} |
|
|
} |
|
|
//字体格式 |
|
|
|
|
|
String FONT = templatePath + "template" + File.separator + "simsun.ttc"; |
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder(); |
|
|
StringBuilder stringBuilder = new StringBuilder(); |
|
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(templateHtmlInputStream, StandardCharsets.UTF_8)); |
|
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(templateHtmlInputStream, StandardCharsets.UTF_8)); |
|
|
String line; |
|
|
String line; |
|
@@ -93,7 +92,7 @@ public class PdfUtils { |
|
|
ITextRenderer renderer = new ITextRenderer(); |
|
|
ITextRenderer renderer = new ITextRenderer(); |
|
|
renderer.setDocument(url); |
|
|
renderer.setDocument(url); |
|
|
ITextFontResolver fontResolver = renderer.getFontResolver(); |
|
|
ITextFontResolver fontResolver = renderer.getFontResolver(); |
|
|
fontResolver.addFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); |
|
|
|
|
|
|
|
|
fontResolver.addFont(fontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); |
|
|
renderer.layout(); |
|
|
renderer.layout(); |
|
|
renderer.createPDF(os); |
|
|
renderer.createPDF(os); |
|
|
os.flush(); |
|
|
os.flush(); |
|
|