Closed sammyhajomar closed 7 months ago
Hello. react-to-print
doesn't interact with your build system or framework in any way. We just take whatever styles exist currently on the page. I would guess that the styles you need aren't being included properly in your production build. This is almost certainly an issue with your next.js configuration, which unfortunately isn't something I am very familiar with so I can't offer much help. It's probably a better question for StackOverflow honestly: "why are my production styles and dev styles different" etc
@MatthewHerbst but when I do allow for printing of the component using <ReactToPrint/>
, the styles are all there and there is no discrepancy. So it seems to me like the html that is returned in the custom print function is different to the one that is used to print in <ReactToPrint />
Hmm. The same iframe
that is used for the regular printing is also what's given to the print
callback (code), so not sure what would be different about that.
To be clear here: the issue is that the custom print
function isn't getting the right content, or is this still a dev/prod issue
@sammyhajomar In the first 1000 characters of the content you gave for the production environment, the styles are loaded via relative paths and no domain name is specified which may be the reason why the styles are not loaded.
I am utilizing react-to-print to extract the html of a component in order to generate a PDF with the same styles
The issue here is I am getting different outputs for html.outerHTML between dev and prod. In dev, all styles work well, but in a prod build none of the styles are loaded. Not sure if this is a bug with nextjs interacting with react-to-print.
Here are the first 1,000 characters of html.outerHTML:
In dev env:
In prod build: