printThis icon indicating copy to clipboard operation
printThis copied to clipboard

Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0

Open hoba-dafidi opened this issue 3 years ago • 1 comments

Hello, Thank you for your great effort developing this plugin. Here is my print function:

function printResult() {
        $('.mainterminalreport').printThis({
            debug: true,
            printDelay: 15000,
            canvas: true
        });
    }

When I click the Print button, I get this error in my console. Uncaught DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0

This bug points here: this.getContext('2d').drawImage($src[0], 0, 0);

What should I do to resolve this?

hoba-dafidi avatar Aug 03 '22 08:08 hoba-dafidi

Canvas is a bit tricky, as the way printThis works is by copying over elements from the parent page to an iframe. My guess is that some key piece is not being copied into the iframe, creating your error.

jasonday avatar Sep 03 '22 04:09 jasonday