0

I'm trying to print my datatable using javascript and css like this:

<h:commandButton value="#{portal.btnPrint}" type="submit" onclick="javascript: window.print();"/>

<p:dataTable id="tbl" var="item" value="#{myPrins.model}" ...
...
</p:dataTable>

@media print
{
  table { font-size: 80%; }
  #menu, #header, #form, #form_error { display: none; } 
  @page { size: A4 landscape !important; }
  ....
  ....
}

And, if I understand it weel, it's DOM based printing, so it just prints, what is set to be printed and visible on the screen.

Problem is, that I can't handle end of pages: enter image description here

What I've tried and refused:

  • styling row heigth or font size (problem happens again on the next pages)
  • print the table per pages (1st page - print, 2nd page - print atc.). User-enemy for big datatable
  • print header on each page using @media print { thead {display: table-header-group;} } - it works in Firefox only
  • export to XLS (I can't from another reason)
  • page-break-inside: avoid; doesn't work in chrome

How to print whole the datatable at once and automatically split the pages correct?

gaffcz
  • 3,469
  • 14
  • 68
  • 108
  • Duplicate? http://stackoverflow.com/questions/9288802/avoid-page-break-inside-row-of-table And what is MFF? (no results in google related to webdevelopment) – Kukeltje Jul 02 '15 at 07:14
  • I guess MFF stands for Mozilla FireFox. Your best bet is to play with CSS or use a proper library dedicated to printing web pages such as wkhtmltopdf. – Mathieu Castets Jul 02 '15 at 07:56
  • Ahhhh... right... MFF... But if these only work in MFF, and not webkit based browsers, will wkhtmltopdf work? I personally use flyingsaucer and it works great – Kukeltje Jul 02 '15 at 08:28

1 Answers1

0

Emergency solution:

  • Mozilla Firefox
  • css: @media print { tr { page-break-inside: avoid !important; } }

New issues & advantages:

  • Header is automatically on each page
  • Border of table is shifted a bit to the left and top (from 2nd page)
  • => I had to make top and left border of table a bit thicker enough to be visible on next pages:

    css: @media print { table { border-top: 3px solid #ACBECE; .. } }

gaffcz
  • 3,469
  • 14
  • 68
  • 108