MatthewHerbst / react-to-print

Print React components in the browser. Supports Chrome, Safari, Firefox and EDGE

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hidden canvas not being printed

sprietNathanael opened this issue · comments

Hi!
I'm using your module to print custom components that are not displayed. I hide the component's container and pass the ref of the inner component. It works greatly, and allows me to make a print version of what is displayed.
I'm trying to print charts from chartjs lib. I put the chart in the inner component, but when I try to print, nothing happens and I got this error :

index.js:111 Uncaught DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0.
    at HTMLIFrameElement.f.onload (http://localhost:3000/static/js/0.chunk.js:300198:45)

Do you have any idea on how to print canvas elements that are not drawn?

Hi there. Unfortunately I don't know much about drawing to the canvas, let alone a hidden one. This seems like it would find a wider audience if you asked it on StackOverflow. If you ask it there can you please link the question here so that we can see if anyone finds the answer? Thanks! Going to close this since it's not an issue directly with this library, but happy to continue the discussion if there's any input I can provide.

instead of hiding the element with { display: 'none'; }, try using { overflow: hidden; height: 0; }

@MickaelNeves solution works perfectly. Thanks!

Is this still the recommended solution? Can't say it's working in chrome on OSX for me

EDIT: Just kidding. For future viewers, I was having an issue with my refs being passed down the component tree.