Home  โ€บ  Learn  โ€บ  Install

1. Install pdfnative and make one PDF

Before this: nothing. This is the first step.

You need Node.js 22 or newer. Check with node --version.

npm install pdfnative

Create make-pdf.mjs:

import { writeFileSync } from 'node:fs';
import { buildDocumentPDFBytes } from 'pdfnative';

const bytes = buildDocumentPDFBytes({
  title: 'My first PDF',
  blocks: [
    { type: 'heading', text: 'Hello', level: 1 },
    { type: 'paragraph', text: 'This file was made by pdfnative.' },
  ],
});

writeFileSync('hello.pdf', bytes);
console.log('Wrote hello.pdf');
node make-pdf.mjs

What you should have

hello.pdf โ€” a single A4 page with a large Hello and one line of text underneath. Open it in any PDF viewer. If it opens, everything below this page is detail.

Two things worth noticing

You should now be able to generate a PDF file from Node and open it.

Tip: Alt + โ† / โ†’ moves between steps.