登录 注册
当前位置:主页 > 资源下载 > 33 > html转pdfHTML导出PDF中文、ITEXT转HTML为PDF包括中文显示解决方案下载

html转pdfHTML导出PDF中文、ITEXT转HTML为PDF包括中文显示解决方案下载

  • 更新:2024-12-08 22:44:50
  • 大小:11.73MB
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:Java - 后端
  • 格式:ZIP

资源介绍

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 += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += " "; html += "
企业信息
登记日期2006-04-28
纳税人编号HSJIHKS002
有效标志Y
社会信用代码916101317H
评估机关代码盛世
工商注销日期2006-04-28
"; String outputFile = "D:\\pdf\\aa.pdf"; try { itextUtil.htmlCodeComeString("",html,outputFile,""); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("生成结束!!!"); }