做的项目需要制作一个模板用来预览pdf,先下载Pdf再把路径返回到页面显示,网上有挺多的,但是我选用的是 以HTML为模板的方式下载,这样排版格式更加方便。
下载pdf的方法
public String downLoad() {
String outputFile = null;
try {
Map<String, Object> map = new HashMap<String, Object>();
map.put("manuscriptContent", "11111");
map.put("createTime", "2018-12-12");
map.put("creator", "sadas");
map.put("manuscriptName", "asdas");
String pdfPath = System.getProperty("java.io.tmpdir") + "/tempdf";// 获取系统临时目录
outputFile = pdfPath + JodaTimeUtils.getNowDate(JodaTimeUtils.YYYYMMDDHHMMSS) + ".pdf";
String outExcelPath = "d:/pdf";// 模板路径
String template = "showManuscript.html";// 模板名称
PdfGeneraterUtils.generate(outExcelPath, template, map, outputFile);// 生成pdf
/** 10秒后删除预览文件 */
final File file = new File(outputFile);
new Thread() {
public voi