[英]The element type “META” must be terminated by the matching end-tag “</META>”. while generating PDF from XML file using XSL
Am trying to convert XML to PDF document. 我正在尝试将XML转换为PDF文档。 While parsing XML with XSL for generating HTML for PDF creating.
同时使用XSL解析XML以生成用于创建PDF的HTML。 HTML doesnt contain
</meta>
closing tag, due to that am getting the below error HTML不包含
</meta>
结束标记,因为它收到以下错误
Exception in thread "main" org.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using TRaX transformer). org.xml.sax.SAXParseException; lineNumber: 22; columnNumber: 3; The element type "META" must be terminated by the matching end-tag "</META>".
How i can include </meta>
closing tag in HTML 我如何在HTML中包含
</meta>
结束标记
Please find my java code to generate PDF from XML 请找到我的Java代码以从XML生成PDF
public class XMLtoPDF {
public static void main(String[] args)
throws IOException, DocumentException, TransformerException,TransformerConfigurationException,FileNotFoundException {
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource("xsl_html_pagebreak_a.xslt"));
transformer.transform(new StreamSource("xsl_html_pagebreak_input.xml"),new StreamResult(new FileOutputStream("sample3.html")));
String File_To_Convert = "sample3.html";
String url = new File(File_To_Convert).toURI().toURL().toString();
System.out.println(""+url);
String HTML_TO_PDF = "ConvertedFile3.pdf";
OutputStream os = new FileOutputStream(HTML_TO_PDF);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(url);
renderer.layout();
renderer.createPDF(os);
os.close();
}
}
The name org.xhtmlrenderer.util
suggests to me that the library you are using (ITextRenderer) expects XHTML. 名称
org.xhtmlrenderer.util
向我暗示您正在使用的库(ITextRenderer)需要XHTML。 You can get XHTML output from your XSLT transformation by 您可以通过以下方式从XSLT转换中获取XHTML输出:
(a) changing it to use the XHTML output method instead of HTML (a)将其更改为使用XHTML输出方法而不是HTML
(b) changing it to use an XSLT 2.0 processor such as Saxon, because to use the XHTML output method, you need XSLT 2.0. (b)更改它以使用XSLT 2.0处理器(例如Saxon),因为要使用XHTML输出方法,则需要XSLT 2.0。
More specifically, change 更具体地说,改变
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource("xsl_html_pagebreak_a.xslt"));
to 至
TransformerFactory tFactory = new net.sf.saxon.TransformerFactoryImpl();
Transformer transformer = tFactory.newTransformer(new StreamSource("xsl_html_pagebreak_a.xslt"));
transformer.setOutputProperty("method", "xhtml");
Alternatively you might find that changing the serialization method to "xml" will also work; 另外,您可能会发现将序列化方法更改为“ xml”也可以使用; in that case you don't need to change to XSLT 2.0.
在这种情况下,您无需更改为XSLT 2.0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.