Skip to content
On this page

Use Doppio to render a Notion Page, automate Notion to PDF

You can use Notion as a PDF editor and generate a PDF directly with Doppio.

Step ❶

Create your own notion page and make it public:

Notion x Doppio

Introduction

This page is to be downloaded as pdf with renders methods.

Contact Information

Name: {{ name }}

Mail: {{ mail }}

Phone Number: {{ phoneNumber }}

...

Step ❷

Use notion-page-to-html to get HTML content of your page:

js
const NotionPageToHtml = require('notion-page-to-html');

const notionUrl = 'https://www.notion.so/<pageId>';

(async() => {
  const { html } = await NotionPageToHtml.convert(
    notionUrl,
  );
})

Step ❸

Replace your variables:

js
const data = {
  appName: 'Doppio',
  date: (new Date()).toDateString(),
  name: 'John',
  mail: '[email protected]',
  phoneNumber: '06 55 59 05 68'
};

for (const key of Object.keys(data)) {
  html = html.replaceAll(`{{ ${key} }}`, data[key])
}

Step ❹

Use Doppio to render your HTML content in pdf:

js
const request = require('request');

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,
  body: JSON.stringify({
    page: {
      pdf: {
        printBackground: true
      },
      setContent: {
        html: encodedHTML
      },
    }
  })
};

request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

All rights reserved