Skip to content

Instantly share code, notes, and snippets.

@markus-gx
Last active December 1, 2023 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markus-gx/f22eca6478c376c042832773c8d109d3 to your computer and use it in GitHub Desktop.
Save markus-gx/f22eca6478c376c042832773c8d109d3 to your computer and use it in GitHub Desktop.
doppio.sh in Nuxt 3 API Route (Direct PDF Response)
export default defineEventHandler(async (e) => {
const body = {
page: {
pdf: {
printBackground: true,
format: 'A4',
},
goto: {
url: `YOUR_URL`,
},
},
}
const response = await $fetch('https://api.doppio.sh/v1/render/pdf/direct', {
method: 'POST',
body: JSON.stringify(body),
headers: {
Authorization: `Bearer ${doppioApiKey}`,
ContentType: 'application/json',
},
responseType: 'arrayBuffer', // Or use 'blob' if that's more appropriate
})
e.node.res.setHeader('Content-Type', 'application/pdf')
e.node.res.setHeader(
'Content-Disposition',
`attachment; filename="Datenblatt-${product}.pdf"`,
)
e.node.res.write(Buffer.from(response))
e.node.res.end()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment