-
I want to display same canvas on multiple pages.As suggested I tried using useRef(watermark example) but I could only display the canvas when only a single page is rendered and I cant get it to work with multiple pages. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I understand that your intention is to add a watermark to multiple pages. It isn't obvious looking at the code, but you're actually attaching one ref to multiple Page components, and just one ends up getting stored for reference. To work with multiple pages, you will need a more sophisticated solution, like a ref that is an object or an array. Then, canvasRef passed to Page needs to be a specially crafted function that stores the reference under specific object key/array index. The rendering part also needs to be slightly adjusted. Because onRenderSuccess is going to be called n times where n is the number of pages, you will want to draw watermark directly in onRenderSuccess callback. You will need to:
Hope this helps! |
Beta Was this translation helpful? Give feedback.
I understand that your intention is to add a watermark to multiple pages.
It isn't obvious looking at the code, but you're actually attaching one ref to multiple Page components, and just one ends up getting stored for reference.
To work with multiple pages, you will need a more sophisticated solution, like a ref that is an object or an array. Then, canvasRef passed to Page needs to be a specially crafted function that stores the reference under specific object key/array index.
The rendering part also needs to be slightly adjusted. Because onRenderSuccess is going to be called n times where n is the number of pages, you will want to draw watermark directly in onRenderSuccess callback. You…