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.

.html(), how to fit content to single pdf? My div is printing into 3 total pages?

See original GitHub issue

Using the latest version, here:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.1.1/jspdf.umd.min.js" integrity="sha512-/Am09zlYshHgRizY3RkConGj4BsYIdb8mS7r5XAXw0rTiLgGSHzpUHTQBhinWR32C/KzLr749J1xuORzT2JnRA==" crossorigin="anonymous"></script>
</script>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>

	let pdf = new jsPDF('l', 'pt','a4',true);
	pdf.html(document.getElementById('mainClone'), {
		callback: function () {
			pdf.save('test.pdf');
			window.open(pdf.output('bloburl')); // to debug
		}
	});

Essentially it is printing this one element out into 3 pages (landscape). I can’t figure out how to adjust the sizing properly so everything passed into the first param of html() gets used in one page. Anyone have tips on this?

Below are the results of the html table and then the resulting pdf.

https://i.imgur.com/r60rteJ.png

https://i.imgur.com/aSSBLTu.png

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
yamanidevcommented, Oct 11, 2022

Is there a better solution to use text/vectors?

Any updates?

1reaction
HennDevcommented, Sep 23, 2020

Heres code snippet that only outputs to one page.

    const quality = 1 // Higher the better but larger file
    html2canvas(document.querySelector('#html'),
        { scale: quality }
    ).then(canvas => {
        const pdf = new jsPDF('p', 'mm', 'a4');
        pdf.addImage(canvas.toDataURL('image/png'), 'PNG', 0, 0, 211, 298);
        pdf.save(filename);
    });

Thanks, I’ll give it a shot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

html(), how to fit content to single pdf? My div is printing into 3 ...
Essentially it is printing this one element out into 3 pages (landscape). I can't figure out how to adjust the sizing properly so...
Read more >
CSS Printing: Avoiding cut-in-half DIVs between pages?
The advice I can give you is, to accomplish this functionality in FF, wrap the content that you don;t want to break ever...
Read more >
fit-content - CSS: Cascading Style Sheets - MDN Web Docs
The fit-content behaves as fit-content(stretch). In practice this means that the box will use the available space, but never more than ...
Read more >
Designing For Print With CSS - Smashing Magazine
The rule below specifies a default page size of 5.5 by 8.5 inches. If you intend to print a book, perhaps by a...
Read more >
CSS page-break-inside property - W3Schools
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python,...
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