iText Cut between pages in PDF from HTML table

2019-06-06 16:09发布

问题:

I did search a lot in google and docs but can't find a solution for this problem, maybe can you guys help me with this?

I have a pdf from html export and my table data is split between the pages, look at this image:

This is a html to pdf convert export, I am not building this table in the PDF, look:

String htmlString = getTableHtml(tableData);

// Create a buffer to hold the cleaned up HTML
ByteArrayOutputStream htmlOutputStream = new ByteArrayOutputStream();

// Clean up the HTML to be well formed
HtmlCleaner cleaner = new HtmlCleaner();
CleanerProperties props = cleaner.getProperties();
TagNode node = cleaner.clean(htmlString);
new PrettyXmlSerializer(props).writeToStream(node, htmlOutputStream);

// Create the PDF
ITextRenderer renderer = new ITextRenderer();
renderer.setDocumentFromString(new String(htmlOutputStream.toByteArray()));
renderer.layout();
ByteArrayOutputStream pdfOutputStream = new ByteArrayOutputStream();
renderer.createPDF(pdfOutputStream);

How can I fix this?

回答1:

it helped me

<style>
@media print
{
  table { page-break-after:auto }
  tr    { page-break-inside:avoid; page-break-after:auto }
  td    { page-break-inside:avoid; page-break-after:auto }
  thead { display:table-header-group }
  tfoot { display:table-footer-group }
}
</style>

https://stackoverflow.com/a/7763286



标签: itext