I'm trying to print some text using my flying saucer (https://xhtmlrenderer.dev.java.net). The document is generated using DOM-API but when the print starts there is a 'content not allowed in prolog' exception. What is the reason for this exception?
My code is this:
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder;
documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.newDocument();
Element html = document.createElement("html");
document.appendChild(html);
Element body = document.createElement("body");
html.appendChild(body);
for (String paragraph : paragraphs) {
Element paragraphTag = document.createElement("p");
paragraphTag.setTextContent(paragraph);
body.appendChild(paragraphTag);
}
XHTMLPanel panel = new XHTMLPanel();
panel.setDocument(document);
print(new XHTMLPrintable(panel));
The print method takes a Printable and puts it into a PrintJob.