Я следую примеру itextpdf http://itextpdf.com/sandbox/htmlworker/HtmlContentForCell.NoNewLineParagraph нельзя отнести к элементу
У меня есть следующий код:
// Relevant code from main part of the class:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Document document = new Document(PageSize.A4, 40, 40, 40, 40);
PdfWriter writer = PdfWriter.getInstance(document, baos);
document.open();
document.add(buildContent());
document.close();
// method that should provide content to the document.
public PdfPTable buildContent() throws IOException {
InfoList infoList = infoListInstance.get();
PdfPTable table = new PdfPTable(2);
for (InfoListMessage message
: infolistList.getMessages()) {
renderMessageMetadata(message, table);
renderMessageContent(message, table);
}
return table;
}
// method where the problem occurs and exception is thrown in the for-loop line
public void renderMessageContent(
InfoListMessage message,
PdfPTable table) throws IOException {
PdfPCell cell = new PdfPCell();
for (Element e : XMLWorkerHelper.parseToElementList(message.getContent(), null)) {
cell.addElement(e);
}
table.addCell(cell);
}
Линия с для цикла "для (элемент е ..." вызывает следующее исключение:
java.lang.ClassCastException: ком .itextpdf.tool.xml.html.pdfelement.NoNewLineParagraph не может быть приведен к com.itextpdf.text.Element
Почему? Я не могу найти любую информацию об этом за исключением прибегая к помощи.
В этом случае HTML-фрагмент - возвращаемый message.getContent() - я пытался использовать, выглядит оригинально, как это:
<html>
<head></head>
<body>
justrandomtexthere
</body>
</html>