PDF Generation (readable is not async iterable)

Any solutions found? It seems like what is returned in the PDF is not an Buffer, debugging this now more. Edit: Okay so .pdf() doesn't work but this does:
const qoutePdf = await page.createPDFStream({
printBackground: true,
format: 'a4',
});

// Create web compatible readable stream
const { readable, writable } = new TransformStream();

const writer = writable.getWriter();

qoutePdf.on('data', (chunk) => {
writer.write(chunk);
});

qoutePdf.on('end', () => {
writer.close();
});

return new Response(readable, {
status: 200,
headers: {
'Content-Type': 'application/pdf',
},
});
const qoutePdf = await page.createPDFStream({
printBackground: true,
format: 'a4',
});

// Create web compatible readable stream
const { readable, writable } = new TransformStream();

const writer = writable.getWriter();

qoutePdf.on('data', (chunk) => {
writer.write(chunk);
});

qoutePdf.on('end', () => {
writer.close();
});

return new Response(readable, {
status: 200,
headers: {
'Content-Type': 'application/pdf',
},
});
3 Replies
ItsWendell
ItsWendellOP14mo ago
^
Firefox
Firefox14mo ago
I didn't look into it much further after it not working but thank you so much for posting a working snippet! 🙏
ItsWendell
ItsWendellOP14mo ago
@vuurvos I just tweaked it to be a bit more efficient
Want results from more Discord servers?
Add your server