com.itextpdf.text.html.simpleparser.CellWrapper cannot be cast to com.itextpdf.text.Paragraph
来源:互联网 发布:淘宝刷手退款能报警 编辑:程序博客网 时间:2024/06/11 05:15
用itext把html生成pdf的时候,如果html是这样的话:
String content = "<table><tr><td><a>dayna</a></td></tr></table>";就会报错:
Exception in thread "main" java.lang.ClassCastException: com.itextpdf.text.html.simpleparser.CellWrapper cannot be cast to com.itextpdf.text.Paragraph
重现的测试方法:
private static void testATag() throws Exception { Document document = new Document(); PdfWriter.getInstance(document,new FileOutputStream("D:\\dayna.pdf")); document.open(); String content = "<table><tr><td><a>dayna</a></td></tr></table>"; Paragraph p = new Paragraph(); HashMap<String,Object> map = new HashMap<String,Object>(); map.put(HTMLWorker.IMG_PROVIDER, new ImgProvider()); List<Element> list = HTMLWorker.parseToList(new StringReader(content),null,map); for(Element e : list) { p.add(e); } document.add(p); document.close(); }
解决办法:
因为生成的pdf不要求点击里面的链接,所以就简单的把所有的a标签全都去掉了。
private static String handleATag(String content) { content = content.replaceAll("<a.*?>", "").replaceAll("<A.*?>", ""); content = content.replaceAll("</a>", "").replaceAll("</A>", ""); return content; }
来自Oracle的回答:
1. You're using HTMLWorker. We're abandoning HTMLWorker in favor of XML Worker.
2. Your HTML is wrong.
You have:
<table><tr><p>A p-tag where you would expect a td-tag</p></tr></table>
or
<table><tr><div>A div-tag where you would expect a td-tag</div></tr></table>
or something like that; you get the idea ;-)
0 0
- com.itextpdf.text.html.simpleparser.CellWrapper cannot be cast to com.itextpdf.text.Paragraph
- 类型com.itextpdf.text.List不带有参数类型
- Type 'com.itextpdf.text.List' does not have type parameter
- itextpdf
- MapReduce 异常 LongWritable cannot be cast to Text
- itextpdf通过for导出多个pdf出现com.itextpdf.kernel.PdfException: pdf.inderect.object.belong.to.other.pdf.docu
- ClassCastException: $Proxy0 cannot be cast to (com......) 的解决办法
- com.sun.proxy.$Proxy29 cannot be cast to
- com.google.gson.internal.StringMap cannot be cast to
- com.bstek.dorado.data.variant.Record cannot be cast to
- com.alibaba.fastjson.JSONObject cannot be cast to
- .ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to
- com.sun.proxy.$Proxy25 cannot be cast to SessionImplementor
- Spring:com.sun.proxy.$proxy0 cannot be cast to XXX
- com.sun.proxy.$Proxy0 cannot be cast to ** 解决方法
- com.sun.proxy.$Proxy4 cannot be cast to spring.HelloService
- Spring com.sun.proxy.$Proxy6 cannot be cast to
- com.google.gson.internal.LinkedTreeMap cannot be cast to xxx
- 工作杂谈之:增量更新
- 对象拷贝问题
- UIAlertView的使用,以及自动消失
- 1031.Hello World for U
- 数据库备份操作,早就不用SQLDMO了
- com.itextpdf.text.html.simpleparser.CellWrapper cannot be cast to com.itextpdf.text.Paragraph
- Oracle中job的实例
- ARM Fundamentals: Introduction to understanding ARM processors
- Android滑动屏幕
- 现在有T1、T2、T3三个线程,你怎样保证T2在T1执行完后执行,T3在T2执行完后执行
- 用GDB调试程序(二)
- 思杰desktop7.6申请90天试用的License
- 初来炸到,请多多关照
- 在liferay strut2中如何使用session