Puppeteere/Chromium pdf printing ignores css page-breaks in tables - printing

I was browsing the last hours to find a solution for my problem with latest puppeteer (2.0.0) / chromium 78.0.x to get our printing system working. We allow to setup page breaks in tables, which worked find in PhantomJS renderer, but not in the puppeteer/chromium solution.
Beside many little difference in global css and printing PDF header/footer the printing of tables was the last problem (hopefully).
It turns out that the "page-break-before: always" is simply ignored.
Example:
<table>
<thead> ... </thead>
<tbody> ...
<tr style="page-break-before: always;"> ...should be on next page ... </tr>
</tbody>
</table>
Some of the Chrome forum articles point out, this has been solved.
So the question is what is causing the problem.
Regards,
Andre
PS) Later we found now: put a "display: block" on all tags of the table solves the problem. Maybe that helps someone. Any comments on that?
<table style="display: block;">
<thead style="display: block;"> ... </thead>
<tbody style="display: block;"> ...
<tr style="display: block; page-break-before: always;"> ...is now on the next page ... </tr>
</tbody>
</table>

Bad news for the solution we provided above. This destroys the feature of having table headers on each page.
setup 1)
Setting "display: block;" for the thead will disable the feature of having the table header on each page.
==> no page break
setup 2)
Set the thead to "display: table-header-group;" and tbody to "table-row-group" then the chrome will ignore the page-breaks.
==> no table headers on each page
setup 3) Having the thead: "display: table-header-group;" and the tbody: "display: block" is destroying the column structure. The body will be rendered only on the first column.
==> Destroys the table. the body is just in the first column
Here comes our hack to solve the problem. we use setup 3, with this:
- we build a table with just one column
- the column contains a table with all columns we really want to render
- the column widths are set to fix values (that was anyway the case in our rendering system)
<table>
<thead>
<tr>
<td> <table> .... the header of the real table </table> </td>
</tr>
</thead>
<tbody style="display:block;">
<tr>
<td>
<table> .... one row of the real table </table>
<td>
</tr>
<tr>
<td>
<table> .... another row of the real table </table>
<td>
</tr>
</tbody>
</table>

Related

Why the content of my table is still visible when the condition is not set in Thymeleaf?

I want that my table is only visible if the size of the list opleidingen is not null.
But altough the list is empty, he still shows the header of the table and the icons. What do I do wrong?
Thankyou
<table th:if="${opleidingen.size() != 0}">
<theader>
<tr>
<th>Code</th>
<th>Titel</th>
<th>Thema</th>
<th>Delete</th>
<th>Pas Aan</th>
</tr>
</theader>
<tbody>
<tr th:each="opleiding: ${opleidingen}">
<td><span th:text="${opleiding.getCode()}"/></th>
<td><span th:text="${opleiding.getTitel()}"/></th>
<td><span th:text="${opleiding.getThema()}"/></th>
<td><img src="../static/Delete.gif"/></th>
<td><img src="../static/Edit.gif"/></th>
</tr>
</tbody>
</table>
Keeps being visible: the header of the table theader tekst and the images. Why, since there are no items to be shown, the whole table shouldn't be shown?
You need to have Thymeleaf render the template, otherwise, the Thymeleaf specific attributes will not do anything.

How to show two columns in Bootstrap Grid System closer than what the default is

In the following HTML I'm using Bootstrap. The real display as shown in image below has two columns too far apart. How can I make them display a bit closer to each other.
NOTE: For the sake of brevity of this post, I've simplified the html a bit. The real html involves some programming code - such as foreach loop and data fetch from database etc - as that all is not related to this post.
<div class="row">
<div class="col-md-12">
<table class="table table-borderless table-condensed">
<thead>
<tr><th></th><th></th></tr>
</thead>
<tbody>
<tr>
<td class="col-md-2">
item1
</td>
<td class="col-md-10">
<span>item2</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
Display:
UPDATE: If I change first column <td class="col-md-2"> to <td class="col-md-1"> and the second column <td class="col-md-10"> to <td class="col-md-11"> the content in first column gets wrapped (something I don't want since all the content in first column is of fixed length and hence it does not need to be wrapped).
To address your updated code with the first column changed to col-md-1, you can add text-nowrap to solve your wrapping issue:
<td class="col-md-1; text-nowrap">

How to resize a long table attribute for a column

I have a long column attribute in my table, it is a token, and I want it to be displayed in two rows instead of one since the token is taking a lot of table space.
For example: "44b4bf4c01261542c9e34701fe435e55"
Code snippet:
<table class="table table-striped table-hover" id="admin_data_table">
<thead>
<tr>
<th>request</th>
</tr>
</thead>
<tbody>
<tr>
<td><%= #request.token %></td>
</tr>
<tbody>
</table>
How can I make this long value 44b4bf4c01261542c9e34701fe435e55 shorter for example to be like:
44b4bf4c012615
42c9e34701fe
435e55
You could use String's scan method to break it up into bits and then join it back together. Here's an example breaking it up into a maximum of 15 characters per line.
> str = "44b4bf4c01261542c9e34701fe435e55"
=> "44b4bf4c01261542c9e34701fe435e55"
> puts str.scan(/.{0,15}/).join("\n")
44b4bf4c0126154
2c9e34701fe435e
55
This is a frontend view concern. You should use HTML or CSS to deal with the width of the column instead of transforming the data itself.
You can do so by setting the HTML width, for example:
<table class="table table-striped table-hover" id="admin_data_table">
<thead>
<tr>
<th width='10%'>request</th>
</tr>
</thead>
<tbody>
<tr>
<td width='10%'><%= #request.token %></td>
</tr>
<tbody>
</table>
You could use css by:
admin_data_table .token-column { width: 10% }
Or if you still feel like transforming the data generated in the backend, you can split the token string with ruby like this:
<%= #token.each_slice(10) # will produce an array of chunks of 10 characters %>
I agree this is a front-end concern. You could try this in your css
table td
{
table-layout:fixed;
width:20%;
overflow:hidden;
word-wrap:break-word;
}
Hope that helps

check specfic words in the records using cucumber, capybara

In my code they have one table. In that table the row is not fixed. it may added by everyone.
I that table every third column text should be "Pending". It is the condition. I dont know How to check that every third column text have "Pending".
I was trying this. I dont know weather its right or not.
page.should have_selector('tbody tr td:nth-child(3)', text: Pending)
Its my html
<table id="thisis" class="table table-bordered table-striped">
<thead>
<tr>
<th>Name</th>
<th>Default</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>Test1</td>
<td>true</td>
<td>
<span class="label label-success">Pending</span>
</td>
<td>
<span>View</span>
<span>/</span>
<span>Edit</span>
<span>/</span>
<span>Publish</span>
</td>
</tr>
<tr>
<td>test2</td>
<td>true</td>
<td>
<span class="label label-success">Pending</span>
</td>
<td>
<span>View</span>
<span>/</span>
<span>Edit</span>
<span>/</span>
<span>Publish</span>
</td>
</tr>
</tbody>
</table>
Thanks for your valuable answers.
Method 1: Use count
Say you have 10 rows in a page, and given your status columns have class "status". Then
expect(page).to have_css(".status", text: "Pending", count: 10)
Method 2: Use scope
To code a table with data, a convention is to assign unique id to each row at least. This will help lots of functions not only the test.
What you need to do is:
Assign an unique CSS id with data id for each row
Add a "status" class for status column for easy identifying
You view will look like this
<tr id="123-row">
<td>bla blah</td>
<td><span class="label label-success status">Pending</span>
...
</tr>
Then, for test, you can do this in Capybara:
within "##{item.id}-row .status"
expect(page).to have_content("Pending")
end

Does HTML5 ban th cells from tbody?

I have the following markup as a part of a Razor view:
<table>
<caption>Presidents</caption>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Born</th>
<th scope="col">Died</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Washington</th>
<td>1732</td>
<td>1799</td>
</tr>
<!-- etc -->
</tbody>
</table>
With the "target schema for validation" set to HTML5, Visual Studio complains thusly:
Warning 1 Validation (HTML5): Element 'th' must not be nested within element 'tbody tfoot'.
Is this really true? If so, could someone link to the spec?
My understanding was that using <th> for row headers was not just legal but encouraged. It certainly seems fairly common, I could link dozens of tutorials explaining (seemingly sensibly) that it helps with accessibility.
Is this a VS bug? A real change coming with HTML5 (a good one? a bad one?)? What's the story?
My understanding was that using <th> for row headers was not just legal but encouraged
As far as I know, this was always legal in HTML 4 (and possibly its predecessors), and hasn't changed in HTML5.
W3C's HTML5 validator, while still experimental, reports no warnings or errors. Then again, I'm sure the HTML5 validation Visual Studio is using is experimental as well since HTML5 itself hasn't yet been finalized.
The HTML5 spec on marking up tabular data, specifically section 4.9.13, shows the use of <th> within <tbody> and <tfoot> to scope row data:
<table>
<thead>
<tr>
<th>
<th>2008
<th>2007
<th>2006
<tbody>
<tr>
<th>Net sales
<td>$ 32,479
<td>$ 24,006
<td>$ 19,315
<tr>
<th>Cost of sales
<td> 21,334
<td> 15,852
<td> 13,717
<tbody>
<tr>
<th>Gross margin
<td>$ 11,145
<td>$ 8,154
<td>$ 5,598
<tfoot>
<tr>
<th>Gross margin percentage
<td>34.3%
<td>34.0%
<td>29.0%
</table>
So it's perfectly legitimate to have <th> elements inside <tr> elements inside either a <tbody> or <tfoot>. As it should be anyway, since table headings aren't just found on table headers.
The HTML5 spec only requires that it be inside a tr, and the spec actually includes an example with a th nested inside a tbody.
Generally a TH in a THEAD will have a scope value of "col" while a TH in a TBODY will have a scope value of "row".

Resources