skip to Main Content

hello to the whole community, I’m using html2pdf javascript in laravel to extrapolate graphs in pdf format, how can I set page breaks so that everything is arranged on multiple pages? I’ve tried everything but I can’t get it to work. thanks so much in advance community.

This is code :

<script>
    $('#btn-one').click(function() {
        let div = document.querySelector(".tutto");
        html2pdf().from(div).save('dashboard-pers-layout-1.pdf');
    });
</script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

2

Answers


  1. Assuming you are using html2pdf.js library,

    <script>
        $('#btn-one').click(function() {
            let div = document.querySelector(".tutto");
            html2pdf().set({
                pagebreak: { mode: 'avoid-all' }
            }).from(div).save('dashboard-pers-layout-1.pdf');
        });
    </script>
    

    reference: https://ekoopmans.github.io/html2pdf.js/#page-breaks

    Login or Signup to reply.
  2. Define a CSS class that will be used to set the page break. In your HTML or stylesheet, define a class like this:

    .page-break {
        page-break-before: always;
    }
    

    This CSS class uses the page-break-before property to force a page break before an element with this class.

    Apply the .page-break class to the elements within your HTML that you want to have page breaks before them. For example:

    <div class="tutto">
        <!-- Content for the first page -->
        <div class="page-break"></div>
        <!-- Content for the second page -->
        <div class="page-break"></div>
        <!-- Content for the third page -->
        <!-- ... -->
    </div>
    

    By inserting the elements, you are indicating where the page breaks should occur when generating the PDF.

    <script>
        $('#btn-one').click(function() {
            let div = document.querySelector(".tutto");
            html2pdf().from(div).save('dashboard-pers-layout-1.pdf');
        });
    </script>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search