I’m trying to generate a PDF using @react-pdf/renderer
, and I want to directly render the PDF to a Buffer
for further processing (e.g., saving it to a file or sending it as an HTTP response). However, when I call ReactPDF.renderToBuffer
, I get the following error:
TypeError: _react_pdf_renderer__WEBPACK_IMPORTED_MODULE_8__.default.renderToBuffer is not a function
Used the following code to generate the PDF:
const buffer = await ReactPDF.renderToBuffer(<MyDocument />);
2
Answers
That function exist as @mocherfaoui mentioned however isn’t mentioned in the documentation for some reason. Until this is fixed you can do:
I’ll just leave it here, maybe you’ll find it helpful.
Environment
OS: MacOS
Browser: Chrome
Next.js : 14.2.10
React-pdf version : 4.1.5
The task is to generate a pdf on the server and send it in an HTTP response.
Error I encountered
Error: I.Component is not a constructor
The code I used is in the route.ts file.
The solution that helped me ( GitHub – https://github.com/diegomura/react-pdf/issues/2350#issuecomment-1914234934 )
Add to the configuration file next.config.js