Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ihor-hrechka opened this issue May 16, 2019 · 11 comments
Open
Labels

Comments

@ihor-hrechka
Copy link

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!

@Uzlopak
Copy link
Collaborator

Uzlopak commented May 16, 2019

hi,

well this is a bug. jspdf canvas has to get a attribute "ownerDocument" which should be a by reference link to document. Then probably it will break somewhere else :D

@Uzlopak Uzlopak added the Bug label May 16, 2019
@andrescst
Copy link

andrescst commented Dec 12, 2019

Hey, I reproduce this on my local.
I was able to solve the problem with the ownerDocument by editing the canvas.js file and creating a new object property on it.
It seems to be working but the output PDF comes with a black figure with the sizes of the given image.

@andrescst
Copy link

andrescst commented Dec 30, 2019

Hey guys! Here is what I made to solve the undefined 'ownerDocument' on the canvas.
andrescst@c854d7b

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.

@JeffDerk
Copy link

Same issue here... can we expect a fix?

@HackbrettXXX
Copy link
Collaborator

We should probably add this fix to the next release.

@github-actions
Copy link

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.

@HanXHX
Copy link

HanXHX commented Aug 28, 2020

I confirm the issue

@HackbrettXXX
Copy link
Collaborator

@andrescst could you prepare a pull request? We might also try updating to html2canvas@1.0.0-rc.7.

@andruts
Copy link

andruts commented Aug 28, 2020

Hey, I have no longer access to @andrescst account but ill be happy to do it from this one.

@subourbonite
Copy link

@andruts @HackbrettXXX Is there a workaround or timeline for when this will be merged / fixed?

@HackbrettXXX
Copy link
Collaborator

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants