I am using the npm @react-pdf/renderer to convert a pdf content to a string in node js (using the renderToString method from the npm) so i can attach the pdf to an email. The issue is everything i try leads to an error when attempting this.
Try 1: I've tried is creating the pdf on the front end and sending the data to my node server:
pdf.js (front-end)
const MyDoc = () => (
<Document>
<Page>
<Text>React-pdf</Text>
</Page>
</Document>
)
//using firebase to call https callable node functions
functions.httpsCallable('pdfRenderToString')({ htmlElement: <MyDoc /> })
index.js (node)
//call renderToString from react-pdf
exports.pdfRenderToString = functions.https.onCall((data, context) => {
return renderToString(data.htmlElement)
.then(pdf => {
return pdf
})
.catch((err) => console.log(err)) //always hits this error, says 'cannot convert Symbol to string'
})
Try 2: i thought maybe the pdf html must be created on node so i tried that
index.js (node)
const MyDoc = () => (
<Document>
<Page>
<Text>React-pdf</Text>
</Page>
</Document>
)
renderToString(<MyDoc />)
.then()...
.catch...
This method forces me to import React (which i find weird but do it anyways)... This time the firebase functions don't even deploy and show error "Failed to load function definition from source: Failed to generate manifest from function source: SyntaxError: Unexpected token '<'"
I've tried everything the react-pdf docs say and i haven't had the least bit of success.
Anyone know what i'm doing wrong or missing?