mrafiqk / html-pdf-node

187 stars 119 forks source link

How to force page break or set html per page? #79

Closed abelncm closed 1 year ago

abelncm commented 1 year ago

Is there a way to force page break so the next page's content doesn't flow into the previous page?

abelncm commented 1 year ago

Use css page break attribute

tanz98 commented 9 months ago

i already use page-break-after: always; or break-after:page;

still not works, any idea?

here's my code function when call print

    async prints(url, filename, landscape = false) {
        let file = { url };
        let path = Helpers.publicPath('/prints/' + filename)
        await html_to_pdf.generatePdf(file, {
            format: 'A4',
            landscape,
            printBackground: true,
            margin: {
                top: '20px',
                right: '20px',
                bottom: '20px',
                left: '20px'
            }
        }).then(pdfBuffer => {
            console.log('PDF Buffer:-');
            fs.writeFileSync(path, pdfBuffer)
        })
        return path
    }

and this the html code

<div style="page-break-after: always;">Content</div>
<table>Content</table>

here the result https://ibb.co/849gh2h