Pdfmake 在分页时将两行放在一起 table
Pdfmake keep two rows together on page break when to page break on table
对于 pdfmake,我有一个 table,其中每条记录使用两行。例如:
当 table 中断时,它会按每一行中断。但是,我希望它在 table 中的 2 行之后或之前中断,您将这两行放在一页中。
而不是:
我希望这两行在同一页中。有没有办法确保发生这种情况?我试过使用 pageBreakBefore 函数,但是我对它不是很直观,而且网上也没有很好的例子。
var dd = {
content: [
'The following table has nothing more than a body array',
{
style: 'tableExample',
table: {
dontBreakRows:true,
// headerRows:1,
body: [
[{text:'Col', colSpan:3, fillColor:'grey'}, {},{}],
[{text:'Column 1',fillColor:'blue'}, {text:'Column 2',fillColor:'blue'}, {text:'Column 3',fillColor:'blue'}],
['One value goes here', 'Another one here', 'OK?'],
[{text:'Description:\n'+'sdfgdhfjsfgvbnfhjfhjfghjgfjgfjfhjfghjgffghjgfasfsjgkfldshgfkld',colSpan:3}],
['One value goes here', 'Another one here', 'OK?'],
[{text:'Description:\n'+'sdfgdhfjsfgvbnfhjfhjfghjgfjgfjfhjfghjgffghjgfasfsjgkfldshgfkld',colSpan:3}]
,
['One value goes here', 'Another one here', 'OK?'],
[{text:'Description:\n'+'sdfgdhfjsfgvbnfhjfhjfghjgfjgfjfhjfghjgffghjgfasfsjgkfldshgfkld',colSpan:3}]
, ['One value goes here', 'Another one here', 'OK?'],
[{text:'Description:\n'+'sdfgdhfjsfgvbnfhjfhjfghjgfjgfjfhjfghjgffghjgfasfsjgkfldshgfkld',colSpan:3}]
, ['One value goes here', 'Another one here', 'OK?'],
[{text:'Description:\n'+'sdfgdhfjsfgvbnfhjfhjfghjgfjgfjfhjfghjgffghjgfasfsjgkfldshgfkld',colSpan:3}]
, ['One value goes here', 'Another one here', 'OK?'],
[{text:'Description:\n'+'sdfgdhfjsfgvbnfhjfhjfghjgfjgfjfhjfghjgffghjgfasfsjgkfldshgfkld',colSpan:3}]
,
],
}
},
]
}
您可以将这些行定义为单独的 table,每行在根 table 中的一行中。这样,行就不会分开,因为它们在 top-level table
中排成一行
你可以这样处理:
pageBreakBefore: function(currentNode, followingNodesOnPage, nodesOnNextPage, previousNodesOnPage) {
//Here you can change the criteria of pageBreak according to your requirement
if (currentNode.id === 'myid' && (currentNode.pageNumbers.length != 1 || currentNode.pageNumbers[0] != currentNode.pages)) {
return true;
}
//Here you can change the criteria of pageBreak according to your requirement
else if (currentNode.id === 'mySecondid' && currentNode.pageNumbers.length != 1) {
return true;
}
return false;
},
对于 pdfmake,我有一个 table,其中每条记录使用两行。例如:
而不是:
我希望这两行在同一页中。有没有办法确保发生这种情况?我试过使用 pageBreakBefore 函数,但是我对它不是很直观,而且网上也没有很好的例子。
var dd = {
content: [
'The following table has nothing more than a body array',
{
style: 'tableExample',
table: {
dontBreakRows:true,
// headerRows:1,
body: [
[{text:'Col', colSpan:3, fillColor:'grey'}, {},{}],
[{text:'Column 1',fillColor:'blue'}, {text:'Column 2',fillColor:'blue'}, {text:'Column 3',fillColor:'blue'}],
['One value goes here', 'Another one here', 'OK?'],
[{text:'Description:\n'+'sdfgdhfjsfgvbnfhjfhjfghjgfjgfjfhjfghjgffghjgfasfsjgkfldshgfkld',colSpan:3}],
['One value goes here', 'Another one here', 'OK?'],
[{text:'Description:\n'+'sdfgdhfjsfgvbnfhjfhjfghjgfjgfjfhjfghjgffghjgfasfsjgkfldshgfkld',colSpan:3}]
,
['One value goes here', 'Another one here', 'OK?'],
[{text:'Description:\n'+'sdfgdhfjsfgvbnfhjfhjfghjgfjgfjfhjfghjgffghjgfasfsjgkfldshgfkld',colSpan:3}]
, ['One value goes here', 'Another one here', 'OK?'],
[{text:'Description:\n'+'sdfgdhfjsfgvbnfhjfhjfghjgfjgfjfhjfghjgffghjgfasfsjgkfldshgfkld',colSpan:3}]
, ['One value goes here', 'Another one here', 'OK?'],
[{text:'Description:\n'+'sdfgdhfjsfgvbnfhjfhjfghjgfjgfjfhjfghjgffghjgfasfsjgkfldshgfkld',colSpan:3}]
, ['One value goes here', 'Another one here', 'OK?'],
[{text:'Description:\n'+'sdfgdhfjsfgvbnfhjfhjfghjgfjgfjfhjfghjgffghjgfasfsjgkfldshgfkld',colSpan:3}]
,
],
}
},
]
}
您可以将这些行定义为单独的 table,每行在根 table 中的一行中。这样,行就不会分开,因为它们在 top-level table
中排成一行你可以这样处理:
pageBreakBefore: function(currentNode, followingNodesOnPage, nodesOnNextPage, previousNodesOnPage) {
//Here you can change the criteria of pageBreak according to your requirement
if (currentNode.id === 'myid' && (currentNode.pageNumbers.length != 1 || currentNode.pageNumbers[0] != currentNode.pages)) {
return true;
}
//Here you can change the criteria of pageBreak according to your requirement
else if (currentNode.id === 'mySecondid' && currentNode.pageNumbers.length != 1) {
return true;
}
return false;
},