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.

Error in .html() method when element has background-image property

See original GitHub issue

I’m trying to add content from HTML element (with using .html() method) but getting html2canvas error.

Source HTML:

<div id="element-to-print" style="background: url('/Content/Images/page-template.png'); background-size: contain;"></div>

JS:

var doc = new jsPDF({ orientation: 'p', format: 'a4'  });
doc.html(document.getElementById('element-to-print'), {
   callback: function (doc) {
         doc.output('dataurlnewwindow');
   }
}

Error: image image

If remove css property background-image and background-size - everything works fine. What can be the reason?

Thank you in advance!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
andrescstcommented, Jan 4, 2020

Hey guys! Here is what I made to solve the undefined ‘ownerDocument’ on the canvas. https://github.com/andrescst/jsPDF/commit/c854d7b27a9a9296453560a109d22637cd6c2aee

When the background-image attribute from the HTML element to print is removed, the function “resizeImage” is not called because there is no image in the given element. However, I was not able to solve the problem with the output black figure. It seems to be a problem with an html2canvas update.

0reactions
HackbrettXXXcommented, May 12, 2021

@subourbonite a workaround would be to draw the background yourself. There is no timeline for a fix ATM. I personally don’t have time for it currently. But any help is welcome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error in .html() method when element has background-image ...
I'm trying to add content from HTML element (with using .html() method) but getting html2canvas error. ... If remove css property background-image ......
Read more >
Why would the background-image property cause a warning ...
Answer :- Yes; background-image property is recognized by all browsers & the image is still shows in the website but the way we...
Read more >
How to fix CSS background-image not working | HTML/CSS
1. Check that your CSS file is linked correctly in your HTML file. · 2. Make sure the image path is set correctly...
Read more >
HTML DOM Style backgroundImage Property - W3Schools
The backgroundImage property sets or returns the background image of an element. ... The background-color will be used if the image is unavailable....
Read more >
background-position - CSS: Cascading Style Sheets | MDN
The background-position CSS property sets the initial position for each background image. The position is relative to the position layer set ...
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