question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jsPDF generate pdf with multiple pages

See original GitHub issue

Hello everybody. I use these version for jspdf: <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script>

I have big div on my page , example of it is:

 <div id="template_invoice">
    <div id="first_head">
        <div id="logo_invoice" class="has-65">
            <img src="" width="280px">
        </div>
        <div id="main_header_info" class="has-35">
        </div>
    </div>
    <div class="clearFix"></div>
    <div id="second_head">
        <div id="lead_address" class="has-65">
            <span id="lead_name"></span><br>
            <span id="lead_street"></span><br>
            <span id="lead_postcode_city"></span><br>
        </div>
         <div id="lead_invoice_info" class="has-35">
            <div class="span_padding_invoice">
            <span class="invoice_main_span">Rechnungs-Nr.</span>
            <span id="lead_rechnungs_nr" class="right-clmn-span"></span>
            <br>
          ...
                </div>
            <div class="span_padding_invoice lead_total_container">
                <span class="invoice_main_span total_bold">Total</span>
                <span id="lead_total" class="right-clmn-span"></span>
                <br>
            </div>
        </div>
    </div>
    <div id="content_invoice">
 <div id="rechnung_div">
            <h1>Rechnung</h1>
            <p>Rechnungs-Nr. <span id="rechnung_nr"></span> / Kunden-Nr. <span id="kunder_nr"></span> </p>
        </div>
        <table id="product_invoice_table" width="100%">
                <thead>
			<tr>
                <th width="55%">Produkt</th>
                <th width="15%">Menge</th>
                <th width="15%">Preis / Einheit</th>
                <th width="15%">Total</th>
            </tr>
			</thead>
<tbody>
</tbody>
        </table>
     </div>
    <div class="clearFix"></div>
    <div id="footer_invoice">
    </div>
</div>

So I generate pdf file using below code: var doc = new jsPDF('p', 'pt', 'a4'); doc.addHTML($('#template_invoice')[0], function () { var pdf = doc.output('blob'); .... });

All works fine, but if height of cotent is larger then page there are not second,third… other pages. I tried use pagesplit:true, but it works wrong, there are not right font,css and instead of 2 pages I get 4 pages with wrong css.

I need any help to solve this problem, how can I set multiple page for my div?

Thanks very much for help!

Now I get such pdf with pagesplt flag: http://clip2net.com/s/3ObsVZc

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
archervallesfincommented, Dec 7, 2017

Found solution for this issue, its a long shot of debugging and testing but so far I found the line that causing the issue of why only 1 page is generated and the rest are empty.

You need to modify the recent version (as of Dec. 2017) jspdf.min.js itself Look for this code inside the minimized version: this.pdf.internal.getVerticalCoordinateString(this.y),e.color,"Td") then changed it to (just removing the e.color) this.pdf.internal.getVerticalCoordinateString(this.y),"","Td")

Let me know if this solve your issue.

0reactions
Uzlopakcommented, Feb 15, 2018

Solved by PR #1492 Merged on 11 January 2018 Will be part of next version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jsPDF multi page PDF with HTML renderer - Stack Overflow
jsPDF multi page PDF with HTML renderer · 1. Hi guys is there any solution for this? – manipvd · What about single...
Read more >
Generate Multipage PDF using Single Canvas of HTML ...
Here we will discuss an example of jsPDF to convert long HTML page into PDF document which will be generated client-side and download....
Read more >
How to add multiple pages in jspdf | jspdf tutorial | html to pdf
... of application here:https://webninjadeveloper.com/javascript/ jspdf -tutorial-to-add- multiple - pages -inside- pdf -document-in-browser-usi...
Read more >
Converting HTML into Multi-page PDF using JavaScript library
The jsPDF library contains more features to generate PDF documents on the client-side with JavaScript. Multi Page PDF Auto Split ...
Read more >
[JavaScript] How to output PDF with multi pages using jsPDF ...
How to generate PDF with multi pages from HTML using jsPDF and html2canvas. - Need jsPDF and html2canvas libraries.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found