PDFEasy
Client/Server Side PDF-Generator based in PDFKit
- ✅ Client/Server Side Support
- ✅ Write in Typescript
- ✅ Builded with ESBuild and requests with OhMyFetch
- ✅ Browser STDLib
- ✅ Custom Fonts && Purge Unused Fonts
- ✅ Plugins Ready!
Installation
It's simple!
NPM
npm i pdfeasy
YARN
yarn add pdfeasy
PNPM
pnpm add pdfeasy
Simple Example
import pdfeasy, { Utils } from 'pdfeasy'
pdfeasy.new({
document: {
margins: {
top: 40,
bottom: 40,
left: 80,
right: 80
}
},
plugins: [
{
page: [
({ Text, Image }, context, current, total) => {
Text(`${current}/${total}`, { fontSize: 20 }, {
x: context.width / 2,
y: context.height - context.margins.bottom
})
},
({ Text }, context, current, total) => {
Text('A Simple Header', {}, {
x: context.width / 2,
y: context.margins.top - 20
})
}
]
}
]
})
pdfeasy.add([
...Utils.content(),
{ raw: 'Hello PDFEasy!', text: { font: 'Roboto' }},
{ raw: 'https://i.imgur.com/path.png', image: {}},
{ stack: [
{ raw: 'A ', text: {}},
{ raw: 'Simple', text: { bold: true, italic: true }},
{ raw: ' Stack!', text: {}},
]},
{ raw: 'Text without option!' },
])
pdfeasy.addFonts([
{
name: 'Roboto',
normal: 'fonts/Roboto-Regular.ttf',
bold: 'fonts/Roboto-Medium.ttf',
italic: 'fonts/Roboto-Italic.ttf',
bolditalic: 'fonts/Roboto-BoldItalic.ttf'
}
])
pdfeasy.run().then((blob: string) => {
const iframe = document.querySelector('#pdf') as HTMLIFrameElement
iframe.src = blob
}).catch((err: any) => {
console.error(err)
})
See source demo for more explanations
See examples for .pdf results.
See scripts for server-side runner.
Bundles
Uses standard minification
pdfeasy/dist/client.cjs.js
pdfeasy/dist/client.esm.js
pdfeasy/dist/node.cjs.js
pdfeasy/dist/node.esm.js
pdfeasy/dist/node.iife.js
pdfeasy/dist/index.d.ts