html- com.itextpdf.tool.xml.exceptions.

问题描述

com.itextpdf.tool.xml.exceptions.

如题,在做html转换成pdf时出现这个异常,求大神帮助。我没有金币了,如果有就悬赏了!
Exception in thread "main" com.itextpdf.tool.xml.exceptions.RuntimeWorkerException: Invalid nested tag head found, expected closing tag meta.
at com.itextpdf.tool.xml.XMLWorker.endElement(XMLWorker.java:135)
at com.itextpdf.tool.xml.parser.XMLParser.endElement(XMLParser.java:397)
at com.itextpdf.tool.xml.parser.state.ClosingTagState.process(ClosingTagState.java:71)
at com.itextpdf.tool.xml.parser.XMLParser.parseWithReader(XMLParser.java:237)
at com.itextpdf.tool.xml.parser.XMLParser.parse(XMLParser.java:215)
at com.itextpdf.tool.xml.parser.XMLParser.parse(XMLParser.java:204)
at com.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:237)
at com.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:211)
at com.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:251)
at com.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:199)
at com.hejinonline.pdf.HtmlToPdfTest.createPdf(HtmlToPdfTest.java:71)
at com.hejinonline.pdf.HtmlToPdfTest.main(HtmlToPdfTest.java:83)

解决方案

这是代码: public static final String HTML = "E:/1.html";
public static final String DEST = "E:/1.pdf";

    /**
     * Creates a PDF with the words "Hello World"
     * @param file
     * @throws IOException
     * @throws DocumentException
     */
    public void createPdf(String file) throws IOException, DocumentException {
        // step 1
        Document document = new Document();
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        // step 3
        document.open();
        // step 4
        XMLWorkerHelper.getInstance().parseXHtml(writer, document,
                new FileInputStream(HTML), Charset.forName("UTF-8"));
        // step 5
        document.close();
    }

    /**
     * Main method
     */
    public static void main(String[] args) throws IOException, DocumentException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new HtmlToPdfTest().createPdf(DEST);
    }

        HTML
        <html>

.b1{white-space-collapsing:preserve;}<br>
.b2{margin: 0.9847222in 1.0236111in 0.9847222in 1.0236111in;}<br>
.s1{font-weight:bold;}<br>
.p1{text-align:center;hyphenate:auto;font-family:Times New Roman;font-size:16pt;}<br>
.p2{text-align:center;hyphenate:auto;font-family:仿宋_GB2312;font-size:15pt;}<br>
.p3{text-align:center;hyphenate:auto;font-family:楷体_GB2312;font-size:12pt;}<br>
.p4{text-align:justify;hyphenate:auto;font-family:楷体_GB2312;font-size:10pt;}<br>
.p5{text-align:start;hyphenate:auto;font-family:Times New Roman;font-size:10pt;}<br>
.p6{text-indent:0.29166666in;text-align:justify;hyphenate:auto;font-family:Times New Roman;font-size:10pt;}<br>
.td1{width:1.1583333in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}<br>
.td2{width:0.8055556in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}<br>
.td3{width:1.1631944in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}<br>
.td4{width:2.7909722in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}<br>
.td5{width:1.96875in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}<br>
.td6{width:0.8263889in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}<br>
.td7{width:1.9645833in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}<br>
.td8{width:4.759722in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}<br>
.r1{height:0.39375in;keep-together:always;}<br>
.r2{height:1.9708333in;keep-together:always;}<br>
.r3{height:0.67777777in;keep-together:always;}<br>
.r4{height:1.2145833in;keep-together:always;}<br>
.r5{height:1.2361112in;keep-together:always;}<br>
.r6{height:1.2743056in;keep-together:always;}<br>
.t1{table-layout:fixed;border-collapse:collapse;border-spacing:0;}<br>

计算机科学系毕业生论文(设计)管理规定

计算机科学与技术学院

实习答辩请假条

学生姓名

专业班级

学号

联系电话

请假原因

请假时间段

(不超过7天)

年 月 日至 年 月 日

指导教

师意见

签名:

年 月 日

辅导员

意见

签名:

年 月 日

系主任意见

签名:

年 月 日

注:1、请假时需持研究生复试通知单或就聘单位面试通知。

2、该假条一式两份,一份交至专业负责人处,一份交至辅导员处。

解决方案二:

这是代码: public static final String HTML = "E:/1.html";
public static final String DEST = "E:/1.pdf";

    /**
     * Creates a PDF with the words "Hello World"
     * @param file
     * @throws IOException
     * @throws DocumentException
     */
    public void createPdf(String file) throws IOException, DocumentException {
        // step 1
        Document document = new Document();
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        // step 3
        document.open();
        // step 4
        XMLWorkerHelper.getInstance().parseXHtml(writer, document,
                new FileInputStream(HTML), Charset.forName("UTF-8"));
        // step 5
        document.close();
    }

    /**
     * Main method
     */
    public static void main(String[] args) throws IOException, DocumentException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new HtmlToPdfTest().createPdf(DEST);
    }

        HTML
        <html>

.b1{white-space-collapsing:preserve;}<br>
.b2{margin: 0.9847222in 1.0236111in 0.9847222in 1.0236111in;}<br>
.s1{font-weight:bold;}<br>
.p1{text-align:center;hyphenate:auto;font-family:Times New Roman;font-size:16pt;}<br>
.p2{text-align:center;hyphenate:auto;font-family:仿宋_GB2312;font-size:15pt;}<br>
.p3{text-align:center;hyphenate:auto;font-family:楷体_GB2312;font-size:12pt;}<br>
.p4{text-align:justify;hyphenate:auto;font-family:楷体_GB2312;font-size:10pt;}<br>
.p5{text-align:start;hyphenate:auto;font-family:Times New Roman;font-size:10pt;}<br>
.p6{text-indent:0.29166666in;text-align:justify;hyphenate:auto;font-family:Times New Roman;font-size:10pt;}<br>
.td1{width:1.1583333in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}<br>
.td2{width:0.8055556in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}<br>
.td3{width:1.1631944in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}<br>
.td4{width:2.7909722in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}<br>
.td5{width:1.96875in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}<br>
.td6{width:0.8263889in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}<br>
.td7{width:1.9645833in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}<br>
.td8{width:4.759722in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}<br>
.r1{height:0.39375in;keep-together:always;}<br>
.r2{height:1.9708333in;keep-together:always;}<br>
.r3{height:0.67777777in;keep-together:always;}<br>
.r4{height:1.2145833in;keep-together:always;}<br>
.r5{height:1.2361112in;keep-together:always;}<br>
.r6{height:1.2743056in;keep-together:always;}<br>
.t1{table-layout:fixed;border-collapse:collapse;border-spacing:0;}<br>

计算机科学系毕业生论文(设计)管理规定

计算机科学与技术学院

实习答辩请假条

学生姓名

专业班级

学号

联系电话

请假原因

请假时间段

(不超过7天)

年 月 日至 年 月 日

指导教

师意见

签名:

年 月 日

辅导员

意见

签名:

年 月 日

系主任意见

签名:

年 月 日

注:1、请假时需持研究生复试通知单或就聘单位面试通知。

2、该假条一式两份,一份交至专业负责人处,一份交至辅导员处。

解决方案三:

 <html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <style type="text/css">.b1{white-space-collapsing:preserve;}
.b2{margin: 0.9847222in 1.0236111in 0.9847222in 1.0236111in;}
.s1{font-weight:bold;}
.p1{text-align:center;hyphenate:auto;font-family:Times New Roman;font-size:16pt;}
.p2{text-align:center;hyphenate:auto;font-family:仿宋_GB2312;font-size:15pt;}
.p3{text-align:center;hyphenate:auto;font-family:楷体_GB2312;font-size:12pt;}
.p4{text-align:justify;hyphenate:auto;font-family:楷体_GB2312;font-size:10pt;}
.p5{text-align:start;hyphenate:auto;font-family:Times New Roman;font-size:10pt;}
.p6{text-indent:0.29166666in;text-align:justify;hyphenate:auto;font-family:Times New Roman;font-size:10pt;}
.td1{width:1.1583333in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}
.td2{width:0.8055556in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}
.td3{width:1.1631944in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}
.td4{width:2.7909722in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}
.td5{width:1.96875in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}
.td6{width:0.8263889in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}
.td7{width:1.9645833in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}
.td8{width:4.759722in;padding-start:0.075in;padding-end:0.075in;border-bottom:thin solid black;border-left:thin solid black;border-right:thin solid black;border-top:thin solid black;}
.r1{height:0.39375in;keep-together:always;}
.r2{height:1.9708333in;keep-together:always;}
.r3{height:0.67777777in;keep-together:always;}
.r4{height:1.2145833in;keep-together:always;}
.r5{height:1.2361112in;keep-together:always;}
.r6{height:1.2743056in;keep-together:always;}
.t1{table-layout:fixed;border-collapse:collapse;border-spacing:0;}
</style>
  <title>计算机科学系毕业生论文(设计)管理规定</title>
  <meta content="xie" name="author">
 </head>
 <body class="b1 b2">
  <p class="p1"> <span class="s1">计算机科学与技术学院</span> </p>
  <p class="p1"> <span class="s1">实习答辩请假条</span> </p>
  <p class="p2"></p>
  <table class="t1">
   <tbody>
    <tr class="r1">
     <td class="td1"> <p class="p3"> <span>学生姓名</span> </p> </td>
     <td class="td2"> <p class="p3"></p> </td>
     <td class="td3"> <p class="p3"> <span>专业班级</span> </p> </td>
     <td class="td4" colspan="2"> <p class="p3"></p> </td>
    </tr>
    <tr class="r1">
     <td class="td1"> <p class="p3"> <span>学号</span> </p> </td>
     <td class="td5" colspan="2"> <p class="p3"></p> </td>
     <td class="td6"> <p class="p3"> <span>联系电话</span> </p> </td>
     <td class="td7"> <p class="p3"></p> </td>
    </tr>
    <tr class="r2">
     <td class="td1"> <p class="p3"> <span>请假原因</span> </p> </td>
     <td class="td8" colspan="4"> <p class="p3"></p> </td>
    </tr>
    <tr class="r3">
     <td class="td1"> <p class="p3"> <span>请假时间段</span> </p> <p class="p4"> <span>(不超过7天)</span> </p> </td>
     <td class="td8" colspan="4"> <p class="p3"> <span>年 月 日至 年 月 日</span> </p> </td>
    </tr>
    <tr class="r4">
     <td class="td1"> <p class="p3"> <span>指导教</span> </p> <p class="p3"> <span>师意见</span> </p> </td>
     <td class="td8" colspan="4"> <p class="p3"></p> <p class="p3"></p> <p class="p3"></p> <p class="p3"> <span> 签名:</span> </p> <p class="p3"> <span> 年 月 日</span> </p> </td>
    </tr>
    <tr class="r5">
     <td class="td1"> <p class="p3"> <span>辅导员</span> </p> <p class="p3"> <span>意见</span> </p> </td>
     <td class="td8" colspan="4"> <p class="p3"></p> <p class="p3"></p> <p class="p3"></p> <p class="p3"> <span> 签名:</span> </p> <p class="p3"> <span> 年 月 日</span> </p> </td>
    </tr>
    <tr class="r6">
     <td class="td1"> <p class="p3"> <span>系主任意见</span> </p> </td>
     <td class="td8" colspan="4"> <p class="p3"></p> <p class="p3"></p> <p class="p3"> <span> </span> </p> <p class="p3"> <span> 签名:</span> </p> <p class="p3"> <span> 年 月 日</span> </p> </td>
    </tr>
   </tbody>
  </table>
  <p class="p5"> <span>注:1、请假时需持研究生复试通知单或就聘单位面试通知。</span> </p>
  <p class="p5"> <span>2、该假条一式两份,一份交至专业负责人处,一份交至辅导员处。</span> </p>
  <p class="p6"></p>
 </body>
</html>
时间: 2024-10-25 04:18:52

html- com.itextpdf.tool.xml.exceptions.的相关文章

动态jsp页面转PDF输出到页面的实现方法_JSP编程

最近工作中遇到不少问题.总结一下.这段代码主要功能是将一个生成JSP页面转发成PDF输出到页面 需要利用ITEXT String html = ServletUtils.forward(request,response,"/WEB-INF/jsp/depot/print/jhd.jsp"); //转发请求到jsp,返回解析之后的内容而不是输出到浏览器 //System.out.println(html); byte[] pdf = PDFUtils.html2pdf(html); re

xmlworkhelper pdf-XMLWorkHelper将html转换成pdf的时候,有分页,错行怎么处理?求各位大神解决下,着急

问题描述 XMLWorkHelper将html转换成pdf的时候,有分页,错行怎么处理?求各位大神解决下,着急 包如下:import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream; import com.itex

文档在线预览的实现

最近在研究企业文档管理,这个是基本上所有企业都需要的软件,当然也是有很多种解决方案.对于企业文档来说,最基本的需求就是独立存储,共享.这种需求只需要建立一个Windows共享文件夹或者架一个Samba服务器即可实现,无法做复杂的权限管理,统计等.另一种方案就是架一个Web应用,比如SharePoint,就可以实现. 既然是WEB应用,进一步的需求是能够在线查看文档,根据用户需求可能不允许下载,不允许打印文档.这一点微软的高级解决方案是使用RMS,能够设置每个用户的打开权限,是否打印等,要求必须是

[ASP.net MVC] 将HTML转成PDF档案,使用iTextSharp套件的XMLWorkerHelper (附上解决显示中文问题)

原文:[ASP.net MVC] 将HTML转成PDF档案,使用iTextSharp套件的XMLWorkerHelper (附上解决显示中文问题) [ASP.net MVC] 将HTML转成PDF档案,使用iTextSharp套件的XMLWorkerHelper (附上解决显示中文问题) 前言 最近专案又遇到需要制作PDF文件的需求,这次还要额外控制PDF档案的其他功能,我的直觉马上联想到使用iTextSharp来实现 一般使用iTextSharp套件要塞资料到PDF档案里的话,大概要先把Phr

java PPT 转成PDF,中文乱码解决

ppt转成pdf,原理是ppt转成图片,再用图片生产pdf,过程有个问题,不管是ppt还是pptx,都遇到中文乱码,编程方框的问题,其中ppt后缀网上随便找就有解决方案,就是设置字体为统一字体,pptx如果页面是一种中文字体不会有问题,如果一个页面有微软雅黑和宋体,就会导致部分中文方框,怀疑是poi处理的时候,只读取第一种字体,所以导致多个中文字体乱码. 百度和谷歌都找了很久,有看到说apache官网有人说是bug(https://bz.apache.org/bugzilla/show_bug.

ASP.Net MVC——使用 ITextSharp 完美解决HTML转PDF(中文也可以)

前言: 最近在做老师交代的一个在线写实验报告的小项目中,有这么个需求:把学生提交的实验报告(HTML形式)直接转成PDF,方便下载和打印. 以前都是直接用rdlc报表实现的,可这次牵扯到图片,并且更为重要的一点是 PDF的格式得跟学生提交的HMTL页面一样.经过网上查阅资料, 找到了ITextSharp插件. ITextSharp很强大,但是在处理HMTL中的 img标签时,src中只能是绝对路径.  解决方法我写在了另一篇文章中 正文: ITextSharp就不多介绍了.项目的链接下载链接为h

I.MX6 Manufacturing Tool V2 (MFGTool2) ucl2.xml hacking

<!-- * Copyright (C) 2010-2013, Freescale Semiconductor, Inc. All Rights Reserved. * The CFG element contains a list of recognized usb devices. * DEV elements provide a name, class, vid and pid for each device. * * Each LIST element contains a list o

中英文对照学习认识一下XML语言

xml XML was designed to describe data and to focus on what data is.XML 的产生是用来描述数据并关注数据的实质是什么 HTML was designed to display data and to focus on how data looks.HTML 则是用来显示数据,它所关注的是数据显示的效果 What You Should Already Know [ 哪些是你应该已经知道的 ] Before you continue

JSP+XML的技术纲要(3)

js|xml <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />  <%@ taglib uri="..." prefix="tl" %><html><tl:parse id="saleBooks" type="BookInventory"xml="Boo