public class ItextPdfUtils extends Object
| 构造器和说明 |
|---|
ItextPdfUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static ByteArrayOutputStream |
export(String htmlStr)
Export PDF with html string, use the default fontPath(.
|
static void |
export(String htmlStr,
OutputStream os)
Export PDF with html string, use the default fontPath(.
|
static ByteArrayOutputStream |
export(String htmlStr,
String fontPath)
Export PDF with html string
The html freemarker template need set body style, For example: <body style = "font-family: SimSun;"> The sample code: Map<String, Object> data = new HashMap<>(); String htmlStr = FreemarkerUtils.build(Test.class, "/pdf").setTemplate("test.ftl").generate(data); ByteArrayOutputStream pdfOs = ItextPdfUtils.export(htmlStr, fontPath); resp.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("测试", "UTF-8") + ".pdf"); resp.setContentType("application/pdf"); ServletOutputStream outputStream = resp.getOutputStream(); outputStream.write(pdfOs.toByteArray()); |
static void |
export(String htmlStr,
String fontPath,
OutputStream os)
Export PDF with html string
The html freemarker template need set body style, For example: <body style = "font-family: SimSun;"> The sample code: Map<String, Object> data = new HashMap<>(); String htmlStr = FreemarkerUtils.build(Test.class, "/pdf").setTemplate("test.ftl").generate(data); resp.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("测试", "UTF-8") + ".pdf"); resp.setContentType("application/pdf"); ItextPdfUtils.export(htmlStr, fontPath, resp.getOutputStream()); |
public static ByteArrayOutputStream export(String htmlStr)
htmlStr - html stringpublic static void export(String htmlStr, OutputStream os)
htmlStr - html stringos - the output streampublic static ByteArrayOutputStream export(String htmlStr, String fontPath)
htmlStr - html stringfontPath - Save the file path for the font.public static void export(String htmlStr, String fontPath, OutputStream os)
htmlStr - html stringfontPath - Save the file path for the fontos - the output streamCopyright © 2021. All rights reserved.