Return a print function from usePDF#1420
Conversation
|
Thanks for this contribution! I have doubts if this should be added to this hook or can be provided as a separate fn. I'll give this some second thoughts but let me know what you think or if there's another way :) |
|
I just found out this: #1388 (comment) IMO it's a great solution. I'm not a huge fan of bundling all the features inside react-pdf while they can be achieved by third-party libs. This way we can keep this module as small as possible (it's not small already) and at the same time we reduce the amount of code to maintain in this end which it's already a lot. Let me know what you think |
|
print-js is not compatible with NextJS (and possibly any other static generation, but I haven't confirmed), and the maintainer has not responded to an open PR from Mar 1 to merge in a fix. However, it's pretty trivial for users of ReactPDF to do exactly what I did in this function and just pass in the instance.url if you don't feel like it fits into the library. It might be worth putting this example and the print-js version into documentation somewhere though. |
|
Anybody looking here for a fix. I ported library (everything except the Modal functionality, because thats UI IMHO): |
Adds a print function to usePDF to add a hidden iframe to document, assign the pdf url to the iframe, print it, and then remove it.
Updates Readme with a usage example.