Can the template detect a page break?



  • I'm using phantom-pdf and sometimes, when the data content matches a certain scenario, I end up with a page break just before an important part of the document and, as a result, it can get a little lost at the top of the next page. If I add a load of spacing around it, that can have the result of it being pushed onto the next page when it would not have previously so I wondered if there is a way for you to pick up the page break through script or CSS to be able to provide a different style for an element that appears immediately after the page break or is this just wishful thinking?



  • Personnaly I would prefere to force the page break using the following function (added in a global asset helpers) :

    function newPage() {
        return '<div style="display: block; page-break-before: always;"></div>';
    }
    

    then upon meeting certain condition just call it like follow

    <body>
    {{#each items}}
      {{#if condition}}
        {{{newPage}}}
       <some-html>your content</some-html>
      {{/if}}
    {{/each}}
    </body>
    

    I do believe it is the easiest way you can achieve what you seek, hope this will help you!



  • Thanks for the reply!

    I did spot the option to force a page break but it's that condition I think I need to determine that I'm struggling with. It's for a quote template and sometimes you have just a small piece of text followed by the estimate, other times it can be half an essay! I think I need to probably use the length of the quote details and work out at what length I should consider the before forcing a page break. Only I also have manipulation of the text to include line breaks so that may also be hit and miss.

    I'll play around with it and post any ideas I come across that I think may help others.
    Thanks again for the suggestion - it's helped narrow the path :)

    Best Regards


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.