Closed grizlizli closed 11 months ago
Hi,
Hope you are doing well.
Recently, we started using your library in our project.
However, when we tested generating a document with images, we got this error:
\node_modules\pdfmake\build\pdfmake.js:66743 [1] var xhr = new XMLHttpRequest(); [1] ^ [1] [1] ReferenceError: XMLHttpRequest is not defined
Here's our setup:
const html = htmlToPdfMake(HTML, { window, imagesByReference: true }); const docDefinition = { // @ts-ignore content: html["content"], // @ts-ignore images: html["images"], // pageOrientation: "landscape", styles: { "html-h1": { color: "red", background: "white", }, "di-paragraph": { color: "green", }, }, }; const pdfDocGenerator = pdfMake.createPdf(docDefinition); // pdfDocGenerator.download(); pdfDocGenerator.getBuffer(function (buffer) { //fs.writeFileSync("companies.pdf", buffer); res.setHeader("Response-Type", "blob"); res.setHeader("Content-Length", buffer.length); res.setHeader("Content-Type", "application/pdf"); res.setHeader("Content-Disposition", "attachment; filename=quote.pdf"); res.write(buffer, "binary"); res.end(null, "binary"); });
Thanks in advance!
Images generated from a Node process must be provided as a base64, as explained in the documentation:
I agree that my documentation is not super clear…
Thanks for the clarification.
Keep up the awesome work!
Hi,
Hope you are doing well.
Recently, we started using your library in our project.
However, when we tested generating a document with images, we got this error:
Here's our setup:
Thanks in advance!