Skip to content
On this page

Render from HTML as source

Step ❶ : HTML content

You can write your HTML content as a string or extract it from a file.

js
const HTML = `<!DOCTYPE html>
<html>
  <body>
    <h1>This a heading</h1>
    <p>This a paragraph</p>
  </body>
</html>`

Step ❷ : Request

setContent.html property has to 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);
});

All rights reserved