各位大侠:我在使用xhtmlrenderer。jar进行html转换pdf时,报错,请大家帮我看看是什么原因啊,不胜感激~

代码:publicstaticvoidmain(String[]args)throwsException{//TODOAuto-generatedmethodstubSt... 代码:public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String inputFile = "C:\\1.htm";
String url = new File(inputFile).toURI().toURL().toString();
String outputFile = "D:\\test.pdf";
System.out.println(url);
OutputStream os = new FileOutputStream(outputFile);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(url);
// 解决中文支持问题
ITextFontResolver fontResolver = renderer.getFontResolver();
fontResolver.addFont("C:/Windows/Fonts/SIMSUN.TTC",
BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
// 解决图片的相对路径问题
// renderer.getSharedContext().setBaseURL("file:/D:/z/temp/");

renderer.layout();
renderer.createPDF(os);
os.close();

}
错误:错误:“Open quote is expected for attribute "http-equiv" associated with an element type "meta".”
Exception in thread "main" org.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using TRaX transformer). org.xml.sax.SAXParseException: Open quote is expected for attribute "http-equiv" associated with an element type "meta".
at org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:191)
at org.xhtmlrenderer.resource.XMLResource.load(XMLResource.java:71)
at org.xhtmlrenderer.swing.NaiveUserAgent.getXMLResource(NaiveUserAgent.java:211)
at org.xhtmlrenderer.pdf.ITextRenderer.loadDocument(ITextRenderer.java:134)
at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:138)
at test.WordToPdf.main(WordToPdf.java:37)
Caused by: javax.xml.transform.TransformerException: org.xml.sax.SAXParseException: Open quote is expected for attribute "http-equiv" associated with an element type "meta".
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:650)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:279)
at org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:189)
... 5 more
Caused by: org.xml.sax.SAXParseException: Open quote is expected for attribute "http-equiv" associated with an element type "meta".
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1269)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:584)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:638)
... 7 more
展开
 我来答
百度网友c4280be
2011-09-06 · TA获得超过462个赞
知道小有建树答主
回答量:462
采纳率:0%
帮助的人:378万
展开全部
Open quote is expected for attribute "http-equiv" associated with an element type "meta".

说明你html源代码中<meta http-equiv="abc" content="def" /> 有问题,看是不是半角的双引号
确保你传入的是xhtml,普通html可以用nekohtml.jar处理下,转成xhtml
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式