A service to generate very basic pdfs using the pdfmake library. Generating pdfs on the client can be expensive, so pawn off the process to a server.
const headers = new Headers();
headers.append("Content-Type", "application/json");
const docDefinition = {...}
const options = {...}
const json = JSON.stringify({
document: docDefinition,
options,
});
const res = await fetch("https://letspdf.vercel.app/api/make", {
method: 'POST',
headers: headers,
body: json
})
const json = await res.json()
If you're using Typescript you're able to install the type definitions to ensure the data you pass is correct.
yarn add @types/pdfmake
- docDefinition: TDocumentDefinitions
- options: BufferOptions (optional)
If the response was successful, the message
property will contain a base 64 string, from there you need to use a package like b64-to-blob to convert the string to a blob.