C
C
Comport2017-02-01 09:21:15
HTML
Comport, 2017-02-01 09:21:15

How, when generating PDF in wkhtmltopdf, to adjust the last page of the document to correctly transfer the block with captions?

We generate reports in PDF, use wkhtmltopdf - the length of the document is different and often the block with signatures at the end is transferred to a new page, as a result of which the person in charge refuses to sign an empty sheet.
I smoked the manual madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9... a suitable option like "~transfer to a new page in "pieces" of at least N% of the page height" (of course, I was not looking for such a wording directly, but the meaning , I hope, passed) - I did not find it. It would probably be strange for developers to cut such an option, because, rather, this is the task of the HTML document itself (insert breaks).
Next, I went from the side of the document: the first thing that comes to mind is to somehow mark the document with breaks on the HTML side .. Maybe there is some option using CSS to measure the height of the document and insert a gap marking in portions under the A4 format ??
But even this is not the most important thing - to mark up under A4 - this is what wkhtmltopdf itself does by transferring to a new page what does not fit ... The point is to transfer the content for the last page so that only the block with signatures does not remain on it ... Of course - the same thing happens on a regular printer if, for example, send a document from Word'a or from anywhere else. At the same time, the content can be distributed in the same way and only the block with signatures will be transferred to the last page. moved more and the block with signatures did not remain in splendid isolation. At the same time, on the previous pages, these "slightly" of mine were not noticeable ..
The thought comes to the conclusion that you need to do the same thing, only with CSS - after generating HTML, you need to somehow calculate its height (in proportion to the units that will be printed), divide the entire length by the A4 height and calculate the height of the last block, if it is less than or approximately equal to the given one (the given one is the height of the block with captions), then for all previous blocks, reduce the height so that the height of the last block increases and insert breaks into the calculated places...
And you need not to overdo it and not "add" content to the last page in such a quantity that it will not fit on it))) That is, the document may have 5 pages, or maybe 105 pages, and if you cut off just a fix from each pages, then we run the risk of getting N more pages and it’s not a fact that the last one won’t have the same problem with a lone block with signatures ...
In general, I feel that the question goes beyond technology) and goes into the category of logic for solving the problem and dancing with a tambourine)))
I would be grateful for thoughts and advice.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Comport, 2017-02-01
@Comport

In general, I thought about it and am inclined to the option in which, after generating HTML JS, you need to calculate the height of all content, then break this height into A4, find the height of the last sheet on which the block with signatures is located and check: if only the block with signatures is located on the last page signatures, then randomly go through arbitrary pages, put a break in front of the last row of the table (to move the table row to the next page), summing up the height of the shifted rows in parallel. Do this until the height of the shifted lines + the height of the block with captions is >= {height A4 / 2}.
In simple terms - we will shift one row of the table from arbitrary sheets until half of the sheet is filled with them on the last page of the table ...
The solution is certainly not very elegant, but I see no other way.
We can say that my conclusion is a paraphrased wazza's answer (thanks to him for that), only more specific and closer to our realities.

W
wazza, 2017-02-01
@wazza

Try adding a special class in the css for the last block:
And then in the html add everything you need for the last page in this div.alwaysbreak block. That is, so that there is some text with signatures inside, and not just signatures. In this case, this block will always be transferred to a new page.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question