Skip to content

Instantly share code, notes, and snippets.

@rlataguerra
Created August 24, 2023 15:37
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 rlataguerra/6f3799548c0666a33d1cec314d575d02 to your computer and use it in GitHub Desktop.
Save rlataguerra/6f3799548c0666a33d1cec314d575d02 to your computer and use it in GitHub Desktop.
An example for doppio.sh (direct render) with node.js and axios
const axios = require('axios');
async function renderPdfWithDoppio() {
try {
const sourceHtml = "<h1>Hello Doppio</h1>"
const htmlAsBase64 = new Buffer.from(sourceHtml, 'utf8').toString('base64')
const options = {
method: 'POST',
url: 'https://api.doppio.sh/v1/render/pdf/direct',
headers: {
'Authorization': 'Bearer xxxxxxxx',
'Content-Type': 'application/json'
},
encoding: null,
data: { //body
page: {
pdf: {
format: 'Letter',
margin: {
top: 36,
bottom: 72,
left: 54,
right: 54
}
},
setContent: {
html: htmlAsBase64,
waitUntil: 'networkidle0'
}
}
}
}
const response = await axios(options)
console.log(response.data); //outputs the raw binary of the PDF
} catch (error) {
console.error(error);
}
}
renderPdfWithDoppio();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment