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!
TODO for v1
Installation
npm i pdfeasy
Simple Example
import pdfeasy, { Utils } from 'pdfeasy'
pdfeasy.new()
pdfeasy.add([
{ raw: 'Simple text!' },
])
pdfeasy.run({
type: 'client',
clientEmit: 'blob'
}).then((blob: string) => {
const iframe = document.querySelector('#pdf') as HTMLIFrameElement
iframe.src = blob
}).catch((err: any) => {
console.error(err)
})
Content
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: {}},
]},
])
Plugins
pdfeasy.new({
plugins: [{
cover: 'https://i.imgur.com/path.png',
background: (page) => {
return 'https://i.imgur.com/path.png'
},
onBefore: () => {
},
onAfter: () => {
},
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
})
}
]
}]
})
Plugins runs as a queue.
Runner Options
pdfeasy.run({
type: 'client',
clientEmit: 'save'
}).then(() => {}).catch((err: any) => {
console.error(err)
})
pdfeasy.run({
type: 'server',
serverPath: path.resolve(process.cwd() + '/examples')
}).then(() => {}).catch((err: any) => {
console.error(err)
})
Custom Fonts
pdfeasy.addFonts([
{
name: 'Roboto',
normal: 'fonts/Roboto-Regular.ttf',
bold: 'fonts/Roboto-Medium.ttf',
italic: 'fonts/Roboto-Italic.ttf',
bolditalic: 'fonts/Roboto-BoldItalic.ttf'
}
])
Attention! Client-Side version not support relative/absolute font paths at this time.
Resources
See source demo for more explanations
See examples for .pdf results.
See scripts for server-side runner.
Bundles
Attention! Its recommended use explicit imports (import pdfeasy from 'pdfeasy/dist/client.esm.js') in your projects.
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