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 String to PDF not working properly - Page width

See original GitHub issue

Hello all,

I’m currently trying to run a HTML String code to PDF using the latest version. No success so far, the HTML is rendered in PDF with only 20% cover of the page, and not the entire page width.

Here’s how it is being generated:

Generated_PDF

My code:

window.html2canvas = html2canvas; 
window.jsPDF = window.jspdf.jsPDF;

const HTML_STRING = "<h1>This is a title</h1> <p>long lorem ipsum text here...</p>";

var pdf = new jsPDF({
                    orientation: "portrait",
                    unit: "pt",
                    format: 'letter'
                });

pdf.html(HTML_STRING, {
                    callback: function (doc) {
                        doc.save('generated_pdf.pdf')
                    },
                    x: 10,
                    y: 10
                });

Tried with different formats and combinations so far (the orientation needs to be portrait), and also tried to set up the margin options array, but no difference was seen. :(

Currently script order usage:

  • purify.min.js * 2.2.2
  • jspdf.umd.min.js * (latest version)
  • html2canvas.min.js * 1.0.0-rc.7

I appreciate any answer, help or discussion here. Thanks.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
HackbrettXXXcommented, Sep 14, 2021

This should be fixed with the new width and windowWidth options in 2.4.0

0reactions
github-actions[bot]commented, Jun 16, 2021

This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML String to PDF not working properly - Page width #3113
Hello all,. I'm currently trying to run a HTML String code to PDF using the latest version. No success so far, the HTML...
Read more >
Solving formatting issues when converting HTML to PDF
The Muhimbi PDF Converter comes with the ability to convert HTML to PDF. ... HTML that improves the formatting, e.g. a different page...
Read more >
Define PageSize when converting from HTML to PDF
My problem is that the resulting pdf has a page size of 215,9 x 279,4mm (instead of 210 x 297mm) and the margin...
Read more >
Resizing Content During Conversion with Select.Pdf Html to ...
The page width is only an indication of the minimum page width recommended for conversion. If the content does not fit this width,...
Read more >
Troubleshooting - EVO PDF
A possible solutions is to set the HTML viewer width to about 800 pixels or to set the PdfDocumentOptions. FitWidth property to false....
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