面生成pdf说明文档
一、依赖的jar包
fonts.jar、pd4ml.jar、ss_css2.jar
二、功能说明
该功能可将jsp页面,直接转换成pdf文件。不需要做任何其他的配置,只需要前期导入依赖的jar包,然后传入函数需要的url(jsp页面action的地址)和pdf文件名称(包括路径),就可以生成需要的pdf到对应的路径下。
三、使用说明
(1) 将3个依赖的jar包导入工程;
(2) 系统代码
ConvertPdf.class-----基础类
public class ConverterPdf {
// 手动构造HTML代码
public static void generatePDF_1(File outputPDFFile, StringReader strReader) throws Exception {
FileOutputStream fos = new FileOutputStream(outputPDFFile);
PD4ML pd4ml = new PD4ML();
pd4ml.setPageInsets(new Insets(10, 20, 10, 20));
pd4ml.setHtmlWidth(950);
//pd4ml.setPageSize(pd4ml.changePageOrientation(PD4Constants.A4));
pd4ml.setPageSize(PD4Constants.A4);
pd4ml.useTTF("java:fonts", true);
pd4ml.setDefaultTTFs("SimHei", "Arial", "Courier New");
pd4ml.enableDebugInfo();
pd4ml.render(strReader, fos);
}
// HTML代码来自于HTML文件
public static void generatePDF_2(File outputPDFFile, String inputHTMLFileName) throws Exception {
FileOutputStream fos = new FileOutputStream(outputPDFFile);
PD4ML pd4ml = new PD4ML();
pd4ml.setPageInsets(new Insets(5, 20, 20, 20));
pd4ml.setHtmlWidth(1000);
//pd4ml.setPageSize(pd4ml.changePageOrientation(PD4Constants.A4));
pd4ml.setPageSize(PD4Constants.A4);
pd4ml.useTTF("java:fonts", true);
pd4ml.setDefaultTTFs("SimHei", "Arial", "Courier New");
pd4ml.enableDebugInfo();
pd4ml.render("file:" + inputHTMLFileName, fos);
}
}
调用页面的源码:
/**
*
*/
public String getAccountPdfHtml(String aid){
HttpServletRequest request = Struts2Utils.getRequest();
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String url = basePath+"user/guser!accountPdf.action";
//action的参数
NameValuePair[] paras = new NameValuePair[1];
paras[0] = new NameValuePair("aid", aid);
String result = PostHttp.postHttpReturnDoc1(url, paras,null);
return result;
}
public String accountPdf(){
corp = this.corpManager.getCorpByAid(aid);
List<CrUser> users = this.userManager.findCrUserPageByAid(aid, 1, 10).getResult();
Struts2Utils.getRequest().setAttribute("orgInfo", corp);
Struts2Utils.getRequest().setAttribute("orgUserList", users);
return "accountPdf";
}
private String createPdf(String aid ,boolean isSendEmail) {
String html = this.getAccountPdfHtml(aid);
StringReader strReader = new StringReader(html);
String rootPaht = getRootPath();
new FileUtil().createFolder(rootPaht + "/pdfFiles");
new FileUtil().createFolder(rootPaht + "/pdfFiles/" + aid);
String filePath = rootPaht + "/pdfFiles/" + aid + "//账户开立申请表.pdf";
try {
ConverterPdf.generatePDF_1(new File(filePath), strReader);
if(isSendEmail){
this.setAid(aid);
this.sendEmail();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
分享到:
相关推荐
JAVAj将页面生成PDF
wkhtmltopdf,支持web页面生成PDF,比其他pdf生成工具兼容性好一点,易用一点,方便一点。PHP html to pdf
jspdf html页面生成pdf j jspdf html页面生成pdfspdf html页面生成pdf
用于《微信小程序云开发如何将页面生成为pdf?》这篇文章代码下载 https://blog.csdn.net/weixin_42063951/article/details/119735347
PHP代码实现网页转为PDF,可添加新字体,支持图片、背景图、简单的css,包含ttf2ufm.exe和php.exe文件
個人上傳以備參考 JAVA 將頁面 HTML 生成 PDF
废话不说,支持简体中文的打印模块,测试文件是test-unicode.php
2、 pdfWriter2():使用QPdfwriter 和QPainter创建pdf报告,关键是对页面的布局排版。本示例,进行了页眉,页脚,中间内容的排版。页眉左上角为图片logo,页眉右边为页数提示;页脚有生成报告的时间和公司logo布局。 ...
主要介绍了Python实现抓取HTML网页并以PDF文件形式保存的方法,结合实例形式分析了PyPDF2模块的安装及Python抓取HTML页面并基于PyPDF2模块生成pdf文件的相关操作技巧,需要的朋友可以参考下
freemarker html生成pdf 通过freemarker 和html模板生成对应的pdf或者图片 参考使用,欢迎下载
用wkhtmltopdf把网页导为PDF文件,代码测试过了,下载用VS2010可以直接运行使用。
基于qt,用c++编写的程序,可以运行,主要功能是可以把html文件转换成pdf文件格式,点击pro,用qtcreator 打开运行即可
最新layui离线pdf文档layui-v2.68
asp.net生成PDF详解 asp.net生成PDF PDF详解 用C#制作PDF文件全攻略 丽水市汽车运输集团有限公司信息中心 苟安廷 目 录 前 言 3 第一部分 iText的简单应用 4 第一章 创建一个Document 4 第一步 创建一个Document实例...
phantomjs有借鉴有研究。
在项目中实现HTML页面转PDF文件输出,HTML生成PDF文件,HTML生成PDF文件
这是从万方上面下载的,最近在弄这方面的东西所以就下载了一些文章,随便传上来一起分享!
保存网页,图片生成pdf,抓取网页生成pdf,研究这个好几天,终于搞定了分享给大家;可以设置你想抓取的网页,保存为图片后再生产pdf;