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

Option to render as img instead of canvas? #82

Open
awdorrin opened this issue Aug 30, 2023 · 0 comments
Open

Option to render as img instead of canvas? #82

awdorrin opened this issue Aug 30, 2023 · 0 comments

Comments

@awdorrin
Copy link

While trying to print a div containing a component, by using document.getElementById('div-to-print').innerHTML, the graphic data in the canvas is not getting copied over.
I'm currently using a work around, where I copy the canvas data over, converting to an img tag with a toDataURL.

I was thinking, if ng-qrcode could insert a img tag, instead of a canvas, with a flag. It would make things a lot easier.

Example code:

    let pageContents = document.createElement('div');
    pageContents.innerHTML = document.getElementById(divId).innerHTML;

    const canvas = Array.from(document.getElementsByTagName('canvas'));
    const canvasClone = Array.from(pageContents.getElementsByTagName('canvas'))

    for (var i = 0; i < canvas.length; i++) {
      let img = document.createElement('img');
      img.className = canvas[i].className;
      img.style.cssText = canvas[i].getAttribute('style');
      img.src = canvas[i].toDataURL();
      canvasClone[i].parentNode.replaceChild(img, canvasClone[i]);
    };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant