Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RuntimeWorkerException: Invalid nested tag head found, expected closing tag meta

I'm using iText in order to convert html into a pdf, but I keep getting a RuntimeWorkerException thrown at parseXHtml. Here's my code:

Document tempDoc = new Document();
PdfWriter pdfWriter = PdfWriter.getInstance(tempDoc, out);
tempDoc.open();
XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, tempDoc, new ByteArrayInputStream(html.getBytes()));
tempDoc.close();

I'm not too familiar with the differences between HTML and XHTML, so I'm at a bit of a loss as to how I should handle this. Here's the html source if it helps.

like image 514
Drazen Bjelovuk Avatar asked Aug 25 '14 17:08

Drazen Bjelovuk


2 Answers

The error message is pretty clear, you have a <meta> tag in the header that isn't closed which is valid in HTML but not XHTML which is what you are parsing it as. You need to close those, <meta ... />

like image 127
Chris Haas Avatar answered Nov 17 '22 00:11

Chris Haas


Remember to close all meta tags

<meta ... />
like image 1
Flavio Troia Avatar answered Nov 17 '22 00:11

Flavio Troia