各位大侠:我在使用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 展开
// 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 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询