在Java项目中,我将FTL模板转换为HTML。然后,我使用ITEXT(7)将HTML转换为PDF。
HTML有6个部分(逻辑)。 (例如6x < div class =“ someClass”></div>
)。我在一些工具中测试了HTML,以检查关闭DIV标签等。
当我使用时
htmlconverter.converttopdf(msg,new fileOutputStream(strfulloutputpath),converterProperties);
它运行完美,HTML正确转换为PDF。 (有关RGB颜色AMD AMD CSS选择器等的一些流浪错误)
我需要添加页脚和标头,因此我遵循以下示例:
PdfWriter writer = new PdfWriter(strFullOutputPath);
PdfDocument pdfDocument = new PdfDocument(writer);
HtmlConverter.convertToDocument(msg, pdfDocument, converterProperties);
现在,PDF使用标头和页脚生成,但最后一部分丢失了。
我已经尝试评论事件手 - 但最后一节仍然缺少
//pdfDocument.addEventHandler(PdfDocumentEvent.START_PAGE, headerHandler);
//pdfDocument.addEventHandler(PdfDocumentEvent.END_PAGE, footerHandler);
HtmlConverter.convertToDocument(msg, pdfDocument, converterProperties);
//footerHandler.writeTotal(pdfDocument);
pdfDocument.close();
标题是一个简单的文本,并且页脚是一个页面编号,带有“ y页x”。
知道怎么了?
In a java project, I am converting a FTL template to HTML. I then convert the HTML to PDF using Itext (7).
The html has 6 sections (logical). (e.g. 6x <div class="someclass"></div>
). I tested out the html in some tools to check closing div tags etc. Seems fine.
When I use
HtmlConverter.convertToPdf(msg, new FileOutputStream(strFullOutputPath),converterProperties);
It works perfectly and the html is converted properly to PDF. (some stray errors about RGB colors amd css selectors, etc)
I needed to add footer and header so I followed the example at:
https://kb.itextpdf.com/home/it7kb/examples/pdfhtml-header-and-footer-examples
PdfWriter writer = new PdfWriter(strFullOutputPath);
PdfDocument pdfDocument = new PdfDocument(writer);
HtmlConverter.convertToDocument(msg, pdfDocument, converterProperties);
Now the pdf is generated with header and footer, but somehow the last section is missing.
I have tried commenting out the EventHandlers - but still the last section is missing
//pdfDocument.addEventHandler(PdfDocumentEvent.START_PAGE, headerHandler);
//pdfDocument.addEventHandler(PdfDocumentEvent.END_PAGE, footerHandler);
HtmlConverter.convertToDocument(msg, pdfDocument, converterProperties);
//footerHandler.writeTotal(pdfDocument);
pdfDocument.close();
The header is a simple text,and the footer is a Page numbering with style "Page x of Y".
Any idea what is going wrong?
发布评论