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.

The jsPDF html module generates a blank page

See original GitHub issue

The jsPDF module generates a blank page. No matter if it’s an element reference or an HTML string, I always get empty PDFs for some reason.

import jsPDF from 'jspdf';
import html2canvas from 'html2canvas';
window.html2canvas = html2canvas;

var toPdfBtn = document.getElementById('pdf');

toPdfBtn.addEventListener('click', function() {
  var doc = new jsPDF();   

  doc.html(document.body, {
    callback: function (doc) {
      doc.save();
    }
  });
});

Note: The above code in the event listener handler is the same one from the documentation.

This doesn’t seem to work either:

import jsPDF from 'jspdf';
import html2canvas from 'html2canvas';
window.html2canvas = html2canvas;

var toPdfBtn = document.getElementById('pdf');

toPdfBtn.addEventListener('click', function() {
  var doc = new jsPDF();   

  doc.html('<h3>Test</h3>', {
    callback: function (doc) {
      doc.save();
    }
  });
});

I also tried importing html2canvas from a CDN and excluding it from this file (commenting out the 2nd and 3rd line), but that doesn’t work either. I also tried importing both html2canvas and jsPDF from a CDN and that doesn’t seem to work as well.

I am using the following versions of the packages (excerpt from the packages.json file):

  "dependencies": {
    "html2canvas": "^1.0.0-rc.3",
    "jspdf": "^1.5.3"
  }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:8

github_iconTop GitHub Comments

1reaction
rubenx4pcommented, Jun 28, 2021

Same for me. I’m using it in Angular application. “dependencies”: { “html2canvas”: “^1.0.0-rc.7”, “jspdf”: “^2.3.1” }

try downgrading to html2canvas to rc.1 version.

sorry I forgot to mention that it work great on Chrome, blank page happens only in Safari

0reactions
huylethanhcommented, Jan 27, 2022

Same for me. I’m using it in Angular application. “dependencies”: { “html2canvas”: “^1.0.0-rc.7”, “jspdf”: “^2.3.1” }

try downgrading to html2canvas to rc.1 version.

sorry I forgot to mention that it work great on Chrome, blank page happens only in Safari

I got the same issue, because my chrome has grammarly extension.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The jsPDF html module generates a blank page ... - GitHub
I am using jsPdf v2.5.0 to create pdf from html. use doc.html() ... The jsPDF html module generates a blank page when the...
Read more >
JSPDF .html() function returning blank pdf page - Stack Overflow
After trying whole day came with following solution. I think we are getting blank page because of versions of html2canvas.
Read more >
The jsPDF html module generates a blank page - Bountysource
The jsPDF module generates a blank page. No matter if it's an element reference or an HTML string, I always get empty PDFs...
Read more >
Component generates PDF-file with one blank page. What's ...
I have added the PDF Generator (jsPDF) component to our Web. I have followed the How to of the component but when I...
Read more >
Jspdf Always Return Blank In Particular Html File - ADocLib
Convert HTML/CSS Content to a Sleek Multiple Page PDF File Using jsPDF browser based JavaScript web application ... The jsPDF module generates a...
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