Hi
I'm looking for a way to generate a PDF from React code server side. The library complains about the missing window object, wich is as expected in an browserless environment. Can I pass any options so it won't need window to translate html elements to groups?
import { Handler } from '@netlify/functions'
import { parseHTML } from 'linkedom'
import { drawDOM, exportPDF } from "@progress/kendo-drawing"
export const handler: Handler = async (event, context) => {
var test = await getBase64()
return {
statusCode: 200,
body: JSON.stringify({
message: `Error: ${test}!`,
}),
}
}
export async function getBase64(): Promise<string> {
try {
const { window, document } = parseHTML("<p>test</p>");
let group = await drawDOM(document.body, { paperSize: "A4" })
let dataUri = await exportPDF(group)
return dataUri.split(";base64,")[1]
} catch (ex) {
return ex
}