Appearance
Use Doppio to render a Notion page to PDF
You can use Notion as a content editor, turn the page into HTML, and then generate a PDF 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 extract the HTML content of the page:
js
import NotionPageToHtml from 'notion-page-to-html';
const notionUrl = 'https://www.notion.so/<pageId>';
let { 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, value] of Object.entries(data)) {
html = html.replaceAll(`{{ ${key} }}`, value);
}Step ❹
Use Doppio to render your HTML content as a PDF:
js
import { writeFile } from 'node:fs/promises';
const encodedHtml = Buffer.from(html, 'utf8').toString('base64');
const response = await fetch('https://api.doppio.sh/v1/render/pdf/direct', {
method: 'POST',
headers: {
Authorization: 'Bearer <YOUR API KEY>',
'Content-Type': 'application/json',
},
body: JSON.stringify({
page: {
pdf: {
printBackground: true,
},
setContent: {
html: encodedHtml,
},
},
}),
});
if (!response.ok) {
throw new Error(`Doppio error ${response.status}: ${await response.text()}`);
}
await writeFile('notion-page.pdf', Buffer.from(await response.arrayBuffer()));