Pdfmake: how to find when page breaks - dynamically render pdf document

Created on 14 Dec 2017  路  13Comments  路  Source: bpampuch/pdfmake

1)I rendered pdf dynamically, in that scenario pdf content went to next page partially. So is there any event available to identify when the page is break. or any other option to overcome this issue.

image

2) rendered border only for last element, but if page breaks the bottom border not showing.

image

table

Most helpful comment

  1. Using stack and unbreakable: true should do what you want:
var dd = {
    content: 
    [

                {
                    columns: [

                    {

                        text: [
                              { text: 'abcdde', style: 'header' },
                              '\n 123456789 \n [email protected] \n newyork XXXXXXXXX',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                        ],
                        style: 'normal'
                    }


                    ]
            },
            '\n',

{
    unbreakable: true,
    stack: [                
                    {
                        style: 'tableExample',

                        table: {
                            // headers are automatically repeated if the table spans over multiple pages
                            // you can declare how many rows should be treated as headers
                            headerRows: 1,
                            widths: ["16%", "16%", "16%", "16%", "16%", "*"],
                            body: [
                              [{ text: 'Header 1', style: 'tableHeader' }, { text: 'Header 2', style: 'tableHeader' }, { text: 'Header 3', style: 'tableHeader' }, { text: 'Header 4', style: 'tableHeader' }, { text: 'Header 5', style: 'tableHeader' }, { text: 'Header 6', style: 'tableHeader' }],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],

                            ]
                        }
                    },
                    {
                        columns: [
                            {
                                text: '', width: '*'

                            },
                            {

                                layout: 'noBorders',
                                    table: {
                                        // headers are automatically repeated if the table spans over multiple pages
                                        // you can declare how many rows should be treated as headers
                                        //headerRows: 1,
                                        widths: ["auto", "*"],
                                        body: [
                                          [{ text: "subtotal", style: 'total' }, { text: "678.00", alignment:'right', style: 'total' }],
                                          [{ text: "tax", style: 'total' }, { text: "90.00", alignment: 'right', style: 'total' }],
                                          [{ text: "discount", style: 'total' }, { text: "11.25", alignment: 'right', style: 'total' }],
                                          [{ text: "Total", style: 'total' }, { text: "776.25", alignment: 'right', style: 'total' }],
                                           [{ text: "Balance Due", style: 'total', bold: true, }, { text: "Rs. 776.25", alignment: 'right', style: 'total', bold: true }],
                                        ]
                                    },
                                    width: '35%',


                            }
                        ]
                    }
    ]
}


            ],

             styles: {

                normal: {
                    fontSize: 10,

                    margin: [0, 0, 0, 10],
                    lineHeight: 1.25
                },

                header: {
                    fontSize: 12,
                    bold: true,
                    margin: [0, 0, 0, 10],
                    lineHeight: 1.25
                }


            }
        };

All 13 comments

1) Event when page breaked is not available.
2) Please attach example of docDefinition for reproduce (executable on http://pdfmake.org/playground.html).

No reaction.

2) When line is drawed is defined in hLineWidth:

                hLineWidth: function (i, node) {
                    if (i === 0 || i === node.table.body.length) {
                        return 1;
                    }
                    return (i === node.table.headerRows) ? 1 : 0;
                },

Condition/variable for when page is breaked is not available.

yes thanks for the reply.

  1. any idea? how to move the table second page (rendered the content dynamically, so how to prevent the partial content break)
  2. yes, in that scenario i'm not aware how to show horizontal lines.
  1. maybe it could be solved using pageBreakBefore, see description in readme.

not sure how to draw on horizontal line and how to handle above issue using page break function.. will check on that.. meanwhile if anyone got solution please share it.

  1. Using stack and unbreakable: true should do what you want:
var dd = {
    content: 
    [

                {
                    columns: [

                    {

                        text: [
                              { text: 'abcdde', style: 'header' },
                              '\n 123456789 \n [email protected] \n newyork XXXXXXXXX',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                        ],
                        style: 'normal'
                    }


                    ]
            },
            '\n',

{
    unbreakable: true,
    stack: [                
                    {
                        style: 'tableExample',

                        table: {
                            // headers are automatically repeated if the table spans over multiple pages
                            // you can declare how many rows should be treated as headers
                            headerRows: 1,
                            widths: ["16%", "16%", "16%", "16%", "16%", "*"],
                            body: [
                              [{ text: 'Header 1', style: 'tableHeader' }, { text: 'Header 2', style: 'tableHeader' }, { text: 'Header 3', style: 'tableHeader' }, { text: 'Header 4', style: 'tableHeader' }, { text: 'Header 5', style: 'tableHeader' }, { text: 'Header 6', style: 'tableHeader' }],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],

                            ]
                        }
                    },
                    {
                        columns: [
                            {
                                text: '', width: '*'

                            },
                            {

                                layout: 'noBorders',
                                    table: {
                                        // headers are automatically repeated if the table spans over multiple pages
                                        // you can declare how many rows should be treated as headers
                                        //headerRows: 1,
                                        widths: ["auto", "*"],
                                        body: [
                                          [{ text: "subtotal", style: 'total' }, { text: "678.00", alignment:'right', style: 'total' }],
                                          [{ text: "tax", style: 'total' }, { text: "90.00", alignment: 'right', style: 'total' }],
                                          [{ text: "discount", style: 'total' }, { text: "11.25", alignment: 'right', style: 'total' }],
                                          [{ text: "Total", style: 'total' }, { text: "776.25", alignment: 'right', style: 'total' }],
                                           [{ text: "Balance Due", style: 'total', bold: true, }, { text: "Rs. 776.25", alignment: 'right', style: 'total', bold: true }],
                                        ]
                                    },
                                    width: '35%',


                            }
                        ]
                    }
    ]
}


            ],

             styles: {

                normal: {
                    fontSize: 10,

                    margin: [0, 0, 0, 10],
                    lineHeight: 1.25
                },

                header: {
                    fontSize: 12,
                    bold: true,
                    margin: [0, 0, 0, 10],
                    lineHeight: 1.25
                }


            }
        };

thanks
but it's not working when the first table have lots of rows.

issue-1

If you want first table to wrap by pages, can only be used on second table unbreakable: true. Example of usage:

var dd = {
    content: 
    [

                {
                    columns: [

                    {

                        text: [
                              { text: 'abcdde', style: 'header' },
                              '\n 123456789 \n [email protected] \n newyork XXXXXXXXX',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                              '\nYou can also specify accurate widths for some (or all columns). Let\'s make the first column and the last one narrow and let the layout engine divide remaining space equally between other star-columns:\n\n',
                        ],
                        style: 'normal'
                    }


                    ]
            },
            '\n',

                    {
                        style: 'tableExample',

                        table: {
                            // headers are automatically repeated if the table spans over multiple pages
                            // you can declare how many rows should be treated as headers
                            headerRows: 1,
                            widths: ["16%", "16%", "16%", "16%", "16%", "*"],
                            body: [
                              [{ text: 'Header 1', style: 'tableHeader' }, { text: 'Header 2', style: 'tableHeader' }, { text: 'Header 3', style: 'tableHeader' }, { text: 'Header 4', style: 'tableHeader' }, { text: 'Header 5', style: 'tableHeader' }, { text: 'Header 6', style: 'tableHeader' }],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"],
                              ["5000", "4500", "5100", "1500", "9600", "2500"]




                            ]
                        }
                    },


{
    unbreakable: true,
    stack: [                    

                    {
                        columns: [
                            {
                                text: '', width: '*'

                            },
                            {

                                layout: 'noBorders',
                                    table: {
                                        // headers are automatically repeated if the table spans over multiple pages
                                        // you can declare how many rows should be treated as headers
                                        //headerRows: 1,
                                        widths: ["auto", "*"],
                                        body: [
                                          [{ text: "subtotal", style: 'total' }, { text: "678.00", alignment:'right', style: 'total' }],
                                          [{ text: "tax", style: 'total' }, { text: "90.00", alignment: 'right', style: 'total' }],
                                          [{ text: "discount", style: 'total' }, { text: "11.25", alignment: 'right', style: 'total' }],
                                          [{ text: "Total", style: 'total' }, { text: "776.25", alignment: 'right', style: 'total' }],
                                           [{ text: "Balance Due", style: 'total', bold: true, }, { text: "Rs. 776.25", alignment: 'right', style: 'total', bold: true }],
                                        ]
                                    },
                                    width: '35%',


                            }
                        ]
                    }
    ]
}


            ],

             styles: {

                normal: {
                    fontSize: 10,

                    margin: [0, 0, 0, 10],
                    lineHeight: 1.25
                },

                header: {
                    fontSize: 12,
                    bold: true,
                    margin: [0, 0, 0, 10],
                    lineHeight: 1.25
                }


            }
        };

thanks,
that solved the above issue. (table break)
Can you help me on the second issue? (border - how to show the border) - yes, as you mentioned it handled by externally with 'customHorizontalLines' functions in pdf table layout. but don't know how to show the line when page break.

table horizontal line

In that scenario unbreakable will not be work, because what will be happen if the table have lots of rows more than 2 page.

stack + unbreakable did the trick for me. Thanks a lot @liborm85.

stack with unbreakable is amazing

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jkd003 picture jkd003  路  3Comments

kumarandena picture kumarandena  路  3Comments

m-brudi picture m-brudi  路  3Comments

kamilkp picture kamilkp  路  3Comments

ValeSauer picture ValeSauer  路  3Comments