I would need to add page break in case of a paragraph (table, table row) is split between two pages. I mean avoid automatic page brake inside unwanted place. And is it possible to align part of a page vertically? To bottom for example, but only if fits all the content. Footer is not a solution in this case assume.
I just discovered pageBreakBefore function :). But still looking for possibility to align node vertically to the bottom.
Vertical alignment to bottom is not supported. So how do you write, you can use pageBreakBefore.
I'm also looking for a way to mark a paragraph to avoid page breaks inside it. In case there would be a page break inside - use a page break before.
So, an equivalent of CSS:
page-break-inside: avoid;
How can I detect if a content is fit to one page or not (it need more pages)?
@ujtordai I know I'm late, but to leave your question answered there's a property of currentNode called pageNumbers. It's an array containing the numbers of the pages which the current node is split between.
To break before a node if its content is split between pages:
pageBreakBefore: function (currentNode, followingNodesOnPage,
nodesOnNextPage, previousNodesOnPage) {
return currentNode.pageNumbers.length > 1;
}
You probably should also consider if the node is already at the start of the page, because in this case the content can't fit to only one page:
[...]
return previousNodesOnPage.length > 0 && currentNode.pageNumbers.length > 1;
I know I'm even later, but here's my trick.
In the document definition, I have this:
pdfMake.createPdf({
content: [...],
pageBreakBefore(currentNode, followingNodesOnPage, nodesOnNextPage, previousNodesOnPage) {
return currentNode.pageNumbers.length > 1 && currentNode.unbreakable;
}
})
And when I want to make a node "unbreakable", I just do this:
{
stack: ["a stack", "of", "unbreakable", "paragraphs"]
unbreakable: true
}
That way the 4 lines of the stacks are not broken. Of course if your unbreakable object takes the whole page you'll have the same issue described by @pedrohql, in which case you would want to change the pageBreakBefore function to add a previousNodesOnPage.length > 0.
Thanks a lot @coyotte508 , It helped me a lot, I was wondering how to implement page breaking rule for long. Maybe this should be published in the documentation page.
Most helpful comment
@ujtordai I know I'm late, but to leave your question answered there's a property of currentNode called pageNumbers. It's an array containing the numbers of the pages which the current node is split between.
To break before a node if its content is split between pages:
You probably should also consider if the node is already at the start of the page, because in this case the content can't fit to only one page: