简体   繁体   English

使用ITextRenderer生成HTML的PDF表单

[英]PDF Generation form HTML using ITextRenderer

I am using ITextRenderer to generate PDF from html. 我正在使用ITextRenderer从html生成PDF。 However I am getting following exception: 但是我得到以下异常:

Error Can't load the XML resource (using TRaX transformer). org.xml.sax.SAXParseException: Content is not allowed in prolog.

Could you please help me? 请你帮助我好吗?

Any help will be appreciated. 任何帮助将不胜感激。

Thanks in advance. 提前致谢。

It is probably caused by lack of encoding declaration in your xml file 这可能是由于您的xml文件中缺少编码声明引起的

XML file header: <?xml version='1.0' encoding='utf-8'?> You should have something like this ( or other encoding type ) at the very top of your xml file. XML文件头: <?xml version='1.0' encoding='utf-8'?>您应该在xml文件的最顶部有类似这样的内容(或其他编码类型)。

OR 要么

You do not escape special characters 您不能逃脱特殊字符

You haven't mentioned that in which programming language you are working. 您没有提到您使用哪种编程语言。 I am assuming that you are doing this in Java. 我假设您正在用Java执行此操作。 writeNextDocument() lets you render multiple X/HTML documents onto the same PDF. writeNextDocument()使您可以将多个X / HTML文档渲染到同一PDF上。 It doesn't let you paste PDFs together. 它不允许您将PDF粘贴在一起。 The error comes from the XML parser trying to parse the PDF document as an XML document. 错误来自XML解析器,试图将PDF文档解析为XML文档。 The easiest way to do what you want is to render the X/HTML to a PDF with FS and then use iText directly to paste them together (Google will turn up examples of this). 执行所需操作的最简单方法是使用FS将X / HTML渲染为PDF,然后直接使用iText将它们粘贴在一起(Google会提供此类示例)。

https://code.google.com/p/flying-saucer/wiki/FAQPDF#How_can_I_print_multiple_pages_on_to_one_PDF,_if_they_come_from_multiple_documents https://code.google.com/p/flying-saucer/wiki/FAQPDF#How_can_I_print_multiple_pages_on_to_one_PDF,_if_they_come_from_multiple_documents

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM