Prasobh.Kollattu
Prasobh.Kollattu

Reputation: 1691

PDF Generation form HTML using ITextRenderer

I am using ITextRenderer to generate PDF from html. 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.

Upvotes: 1

Views: 2247

Answers (2)

user2854830
user2854830

Reputation: 25

You haven't mentioned that in which programming language you are working. I am assuming that you are doing this in Java. writeNextDocument() lets you render multiple X/HTML documents onto the same PDF. It doesn't let you paste PDFs together. The error comes from the XML parser trying to parse the PDF document as an XML document. 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).

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

Upvotes: 0

Maciej Cygan
Maciej Cygan

Reputation: 5471

It is probably caused by lack of encoding declaration in your xml file

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.

OR

You do not escape special characters

Upvotes: 2

Related Questions