Pdf pdf = new Pdf(); pdf.addPageFromUrl(newUrl); pdf.addParam(new Param("--enable-local-file-access")); pdf.addParam(new Param("--page-size", "A4")); pdf.addParam(new Param("--header-spacing", "3")); pdf.addParam(new Param("--footer-spacing", "6"));
OutputStream os = null; byte[] buff = new byte[1024]; BufferedInputStream bis = null; try { //先临时存储到本地 String pdfFileName = "ExportAll" + System.currentTimeMillis() + ".pdf"; File pdfFile = new File(ExportCommonManager.getUploadFileTempRootPath() + File.separator + pdfFileName); log.info("filePath is {}",ExportCommonManager.getUploadFileTempRootPath() + File.separator + pdfFileName); if(!pdfFile.exists()){ pdfFile.createNewFile(); }
//把pdf的html内容写入到本地临时文件中 pdf.saveAs(pdfFile);
//导出pdf文件 exportCommon(response, pdfFileName);
os = response.getOutputStream(); bis = new BufferedInputStream(new FileInputStream(pdfFile)); int i = 0; while ((i = bis.read(buff)) != -1) { os.write(buff, 0, i); } os.flush();