README
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!
Documentation is under construction!
Installation
It's simple!
NPM
npm i pdfeasy
YARN
yarn add pdfeasy
PNPM
pnpm add pdfeasy
Simple Example
pdfeasy.new({
document: { // PDFKit options
margins: {
top: 40,
bottom: 40,
left: 80,
right: 80
}
},
plugins: [ // Plugins!
{
page: [ // render callback in every page AFTER finish contents insert. Not support before at this time.
// simple counter footer
({ Text, Image }, context, current, total) => {
// render in every page
Text(`${current}/${total}`, { fontSize: 20 }, {
x: context.width / 2,
y: context.height - context.margins.bottom
})
// Image('https://i.imgur.com/J3JXhsl.png', {}, {})
},
// simple header
({ Text }, context, current, total) => {
// render in every page
Text('A Simple Header', {}, {
x: context.width / 2,
// negative number (-30 in case) ignore default margins
y: context.margins.top - 20
})
}
]
}
]
})
pdfeasy.add([
...Utils.content(), // Utils for debug
{ raw: 'Hello PDFEasy!', text: { font: 'Roboto' }}, // custom font,
{ raw: 'https://i.imgur.com/GbmBw3N.png', image: {}}, // external image
{ stack: [ // stack for paragraph's
{ raw: 'A ', text: {}},
{ raw: 'Simple', text: { bold: true, italic: true }},
{ raw: ' Stack!', text: {}},
]},
// not recommended use this
{ raw: 'Text without option!' },
])
// or https://path/to/Roboto.ttf
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({
client: {
emit: 'blob'
}
}).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 minifications
pdfeasy/dist/client.cjs.sj
pdfeasy/dist/client.esm.sj
pdfeasy/dist/node.cjs.sj
pdfeasy/dist/node.esm.sj
pdfeasy/dist/node.iife.sj
pdfeasy/dist/index.d.ts