1、解决中文问题
2、附字体
3、动态html拼接转pdf
public static void htmlCodeComeString(String linkcss,String htmlCode, String outputFile,String title) throws Exception {
OutputStream os = new FileOutputStream(outputFile);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocumentFromString(getConversionHtmlCode(linkcss,htmlCode,title));
ITextFontResolver fontResolver = renderer.getFontResolver();
URL fontPath = ItextUtil.class.getResource("simsun.ttc");
fontResolver.addFont(fontPath.toString(), BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
// 解决图片的相对路径问题
// renderer.getSharedContext().setBaseURL("file:/F:/teste/html/");
renderer.layout();
renderer.createPDF(os);
System.out.println("======转换成功!");
os.close();
os.flush();
}
public static void main(String[] args)
{
ItextUtil itextUtil = new ItextUtil();
String html = "";
html += "
";
html += "企业信息";
html += " ";
html += " ";
html += " 登记日期 | ";
html += " 2006-04-28 | ";
html += "
";
html += " ";
html += " 纳税人编号 | ";
html += " HSJIHKS002 | ";
html += "
";
html += " ";
html += " 有效标志 | ";
html += " Y | ";
html += "
";
html += " ";
html += " 社会信用代码 | ";
html += " 916101317H | ";
html += "
";
html += " ";
html += " 评估机关代码 | ";
html += " 盛世 | ";
html += "
";
html += " ";
html += " 工商注销日期 | ";
html += " 2006-04-28 | ";
html += "
";
html += " ";
html += "
";
String outputFile = "D:\\pdf\\aa.pdf";
try
{
itextUtil.htmlCodeComeString("",html,outputFile,"");
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("生成结束!!!");
}