Skip to content

Render from raw HTML ​

Step ❶: Prepare the HTML content ​

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 ❷: Encode as Base64 and send the request ​

The setContent.html property must be Base64-encoded.

With native fetch (Node.js 22+) ​

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('output.pdf', Buffer.from(await response.arrayBuffer()));

With the official Node.js SDK (doppio-nodejs) ​

js
import { writeFile } from 'node:fs/promises';
import { Doppio } from 'doppio-nodejs';

const client = new Doppio(process.env.DOPPIO_API_KEY);
const encodedHtml = Buffer.from(html, 'utf8').toString('base64');

const pdfBuffer = await client.renderPdfDirect({
  pdf: { printBackground: true },
  setContent: { html: encodedHtml },
});

await writeFile('output.pdf', Buffer.from(pdfBuffer));

All rights reserved