• TypeScript 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Mikkel ALMONTE--RINGAUD d06bdfc344
Some checks failed
Checks / checks (push) Has been cancelled
chore(ci): oops
2025-09-24 08:56:20 +02:00
.github/workflows chore(ci): add checks and publish 2025-09-09 09:43:58 +02:00
.vscode chore: add eslinter 2025-09-09 09:44:20 +02:00
examples chore: add eslinter 2025-09-09 09:44:20 +02:00
src refactor: into multiple files 2025-09-09 09:50:34 +02:00
tests chore(ci): oops 2025-09-24 08:56:20 +02:00
.gitignore chore: ignore example pdfs 2025-09-09 09:00:25 +02:00
bun.lock chore: prepare release 2025-09-09 10:02:15 +02:00
eslint.config.ts chore: add eslinter 2025-09-09 09:44:20 +02:00
LICENSE chore: add license 2025-09-09 09:58:02 +02:00
package.json chore: release v0.1.0 2025-09-09 10:02:26 +02:00
README.md docs: add contributing section 2025-09-09 09:55:24 +02:00
tsconfig.json chore: paths for tsconfig and bundler 2025-09-09 09:50:53 +02:00
tsup.config.ts chore: paths for tsconfig and bundler 2025-09-09 09:50:53 +02:00

Pagiko

Installation

bun add pagiko

Quick Start

You can quickly get started by creating an empty PDF.

import { pdf, page } from "pagiko";
const file = pdf().child(page());

Here, we created a PDF document with a single page. Once you've done with your layout, you can render the file into bytes.

const bytes = await file.renderToBytes();
//    ^ UInt8Array

With those bytes, you can write the file to your filesystem for example.

import { writeFile } from "node:fs/promises";
await writeFile("document.pdf", bytes);

But since this library also works in browsers, you can use whatever method you like to display or download the PDF depending on your needs.

API

pdf() - create a new document

.author() - set the author of the document

Set document's author metadata. The author will appear in the document properties section of most PDF readers.

pdf().author("Vexcited");

.font() - load a font to later use

This will add the font to the document, needed when you want to use a custom font later on. The default font is Helvetica.

import { pdf, font, StandardFonts } from "pagiko";
const times = font(StandardFonts.TimesRoman);

const buffer = new Uint8Array(/* ...a font file... */);
const custom = font(buffer);

// Load both fonts to be later used.
pdf().font(times).font(custom);

.child() - add a new page to document

Just like a tree, if you want to add pages to your document, you must use child for each page.

import { page } from "pagiko";

pdf()
  .child(page()) // Page 1
  .child(page()); // Page 2

page() - create a new page

.h() - set the height

Define a new height for the page, provided in pt.
Defaults to 841.89 which is the height in pt for an A4.

page().h(100.5);

.w() - set the width

Define a new width for the page, provided in pt.
Defaults to 595.28 which is the width in pt for an A4.

page().w(200.25);

.size() - set the width and height at the same time

Define a new width and height for the page, provided in pt.
Defaults to [595.276, 841.8898] which the width and height in pt for an A4.

import { PageSizes } from "pagiko";

page().size([200.25, 100.5]);
page().size(PageSizes.A7);

.child() - add elements to the page

Add elements to the root of the page, you can chain this function to add multiple elements to the root.

import { div, text } from "pagiko";

page
  .child(div()) // Add an empty div to the page
  .child(text("")); // Add an empty text to the page

Contributing

Quick Start

git clone https://github.com/Vexcited/Pagiko && cd Pagiko

bun install
bun run ./examples/... # run any example!

Release

I am using Mentor to automatically create releases for this package.

mentor

We're using semver for versioning.