Appearance
Render from raw HTML
Step ❶: Prepare the HTML content
You can write your HTML as a string or load it from a file.
js
const HTML = `<!DOCTYPE html>
<html>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph</p>
</body>
</html>`Step ❷: Build the request
The setContent.html property must be base64-encoded.
js
const encodedHTML = new Buffer.from(html, 'utf8').toString('base64')
const options = {
method: 'POST',
url: 'https://api.doppio.sh/v1/render/pdf/direct',
headers: {
'Authorization': 'Bearer <YOUR API KEY>',
'Content-Type': 'application/json'
},
encoding: null, // necessary to receive binary data
body: JSON.stringify({
page: {
pdf: {
printBackground: true
},
setContent: {
html: encodedHTML
}
}
})
};js
const request = require('request');
request(options, function (error, response) {
if (error) throw new Error(error);
});