iText~html转pdf出现异常:com.itextpdf.tool.xml.exceptions.RuntimeWorkerException: Inva
public static void parseHTML2PDFFile(String pdfFile,
String htmlFile) {
try{
File htmlfile = new File(htmlFile);
InputStream htmlFileStream = new FileInputStream(htmlfile);
BaseFont bfCN = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H",false);
// 中文字体定义
Font chFont = new Font(bfCN, 12, Font.NORMAL, BaseColor.BLUE);
Font secFont = new Font(bfCN, 12, Font.NORMAL, new BaseColor(0, 204,
255));
Document document = new Document();
PdfWriter pdfwriter = PdfWriter.getInstance(document,
new FileOutputStream(pdfFile));
pdfwriter.setViewerPreferences(PdfWriter.HideToolbar);
document.open();
// html文件
InputStreamReader isr = new InputStreamReader(htmlFileStream, "UTF-8");
//默认参数转换
XMLWorkerHelper.getInstance().parseXHtml(pdfwriter, document, isr);
document.close();
}catch (Exception e) {
e.printStackTrace();
}
}
com.itextpdf.tool.xml.exceptions.RuntimeWorkerException: Invalid nested tag head found, expected closing tag link.
at com.itextpdf.tool.xml.XMLWorker.endElement(XMLWorker.java:134)
at com.itextpdf.tool.xml.parser.XMLParser.endElement(XMLParser.java:393)
at com.itextpdf.tool.xml.parser.state.ClosingTagState.process(ClosingTagState.java:70)
at com.itextpdf.tool.xml.parser.XMLParser.parseWithReader(XMLParser.java:235)
at com.itextpdf.tool.xml.parser.XMLParser.parse(XMLParser.java:213)
at com.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:168)
at com.hoosen.webquery.action.WordToHtml.parseHTML2PDFFile(WordToHtml.java:128)
at com.hoosen.webquery.action.WordToHtml.main(WordToHtml.java:156)