Created
August 24, 2023 15:37
-
-
Save rlataguerra/6f3799548c0666a33d1cec314d575d02 to your computer and use it in GitHub Desktop.
An example for doppio.sh (direct render) with node.js and axios
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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