api/pdf/index.ts
Content-Disposition in this way will result in the PDF being downloaded. Removing attachment will serve the PDF in browser.Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
How to respond with a PDF from an API route
const result = await fetch("https://pdf.service", {
headers: {
Accept: "application/pdf"
}
})
// Do your error handling
response.writeHead(200, {
'Content-Type': 'application/pdf',
'Content-Disposition': 'attachment; filename="filename.pdf"'
})
response.end(
Buffer.from(await result.arrayBuffer())
)
Content-Disposition in this way will result in the PDF being downloaded. Removing attachment will serve the PDF in browser.