-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loosing Data between two pages #2826
Comments
The issue occurs because the // playground requires you to assign document definition to a variable called dd
let __content = [];
for(let i = 0; i < 50; i++) {
__content[i] = [{
id: `lig_${i}`,
text: `line ${i} => Line Content N° : ${i}\n\t\t\t\tMultiline : true\n\t\t\t\tpreserveLeadingSpaces : true`,
preserveLeadingSpaces: true,
}];
}
var dd = {
content: [
{
table: {
dontBreakRows: true,
keepWithHeaderRows: 1,
headerRows: 1,
// Define width to prevent overflow
widths: ['*'],
body: __content
},
layout: {
hLineWidth: function(i, node) {
return 1;
},
vLineWidth: function(i, node) {
return 1;
},
paddingTop: function(i, node) {
return 4;
},
paddingBottom: function(i, node) {
return 4;
}
}
}
],
// Instead of using pageBreakBefore, use pageSize and margins
pageSize: 'A4',
pageMargins: [40, 40, 40, 40]
}; Key changes made to fix the issue:
If you still need to maintain specific control over page breaks, you could use this alternative approach:var dd = {
content: [
{
table: {
dontBreakRows: true,
widths: ['*'],
body: __content
}
}
],
pageSize: 'A4',
pageMargins: [40, 40, 40, 40],
pageBreakBefore: function(currentNode, followingNodesOnPage) {
if (currentNode.table) {
// Only break if we're at least 50 units from the bottom
return currentNode.startPosition.top > 700;
}
return false;
}
}; Additionally, if you're dealing with large datasets, you might want to consider splitting your content into multiple tables:function splitIntoChunks(array, chunkSize) {
let chunks = [];
for (let i = 0; i < array.length; i += chunkSize) {
chunks.push(array.slice(i, i + chunkSize));
}
return chunks;
}
let tableChunks = splitIntoChunks(__content, 10);
var dd = {
content: tableChunks.map(chunk => ({
table: {
dontBreakRows: true,
widths: ['*'],
body: chunk
},
pageBreak: 'after' // except for last chunk
})),
pageSize: 'A4',
pageMargins: [40, 40, 40, 40]
}; This approach gives you more control over where the breaks occur while ensuring no data is lost. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
First of all, I want to thank you for your work!
really and sincerely a big Thank you.
I encounter a strange phenomenon.
You will be able to see it thanks to this piece of code in the playground.
Between 2 pages we lose 1 line of data
In my example I lose the lines:
9,19,29,39,49
This is mainly due to the use of the "pageBreakBefore" function which returns this behavior to me
Setting dontBreakRows to false bring long empty box, setting dontBreakRows to true bring this behavior !
What is the good way to do it ?
The text was updated successfully, but these errors were encountered: