Image rendering on Node backend does not work
See original GitHub issueDescribe the bug
I am generating the pdf on the backend using the example from the website
await renderToFile(<MyDocument />,
${__dirname}/my-doc.pdf);
but i am unable to use the Image component. I have tried to use external images and also internal images but i see an empty space. I have tried the same code on the frontend with React and the Pdf is generated correctly, i have tried even with the PdfDownloadLink and it correctly renders the image.
To Reproduce
- generate an express app with nodejs
- generate a route where you return or generate the Pdf
const router = express.Router();
router.post(
"/api/printTest",
asyncHandler(async (req: Request, res: Response) => {
try {
const { source } = req.body as { source: any};
const string = await renderToString(<DocumentWithImage source={source} />);
// or await renderToFile(<DocumentWithImage source={source} />, `${__dirname}/my-doc.pdf`);
res.send(string);
} catch (error) {
res.status(400).send(new Error("PDF Error Generation"));
}
})
);
export { router as printRouter};
Expected behavior I should see the image inside the Pdf
Desktop (please complete the following information):
- OS: [ Windows 10]
- Browser [ chrome,]
- React-pdf version [ v2.0.4]
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:18 (9 by maintainers)
Top Results From Across the Web
React: Image uploaded from node js backend is not rendering
The Account page makes a GET request to the backend retrieves the path however I can't get the image to display. The path...
Read more >Images in my /public folder not rendering correctly
I deployed my node.js backend on render.com and it has a “/public” folder with all the images that are supposed to be called...
Read more >How to fetch images from Node.js server ? - GeeksforGeeks
The image to be accessed (geeksforgeeks.png) is placed inside the images folder, ... Run the server.js file using the following command:
Read more >Why the Hell Would I Use Node.js? A Case-by-case Tutorial
Node.js can solve I/O scaling, but was not created to compute scaling problems. Learn why and when to use Node.js in this case-by-case...
Read more >Backend rendering of a preview image - three.js forum
I have a working threejs-based viewer an now i like to generate ... to a image by click on a button on the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was able to achieve what you want by rendering using the
renderToStream
function:@diegomura I’m able to reproduce the same issue in the latest version
2.0.20
as well. TherenderToString
does not render the images at all.Here is a screenshot of the output PDF: