Error in .html() method when element has background-image property
See original GitHub issueI’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:
If remove css property background-image
and background-size
- everything works fine. What can be the reason?
Thank you in advance!
Issue Analytics
- State:
- Created 4 years ago
- Comments:11
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
@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.