@@ -10,7 +10,6 @@ Client/Server Side PDF-Generator based in PDFKit
1010<h4 >
1111<br >
1212<p align =" center " >
13- <a ><img src =" https://img.shields.io/github/workflow/status/Novout/pdfeasy/Tests?style=for-the-badge&color=5cb4f8& " ></a >
1413 <a ><img src =" https://img.shields.io/github/license/Novout/pdfeasy?style=for-the-badge&color=5cb4f8&label= " ></a >
1514<p >
1615
@@ -26,26 +25,12 @@ Client/Server Side PDF-Generator based in PDFKit
2625
2726## Installation
2827
29- It's simple!
30-
3128### NPM
3229
3330``` shell
3431npm i pdfeasy
3532```
3633
37- ### YARN
38-
39- ``` shell
40- yarn add pdfeasy
41- ```
42-
43- ### PNPM
44-
45- ``` shell
46- pnpm add pdfeasy
47- ```
48-
4934## Simple Example
5035
5136``` ts
@@ -62,47 +47,105 @@ pdfeasy.new({
6247 left: 80 ,
6348 right: 80
6449 }
65- },
66- plugins: [ // Plugins!
67- {
68- page: [ // render callback in every page AFTER finish contents insert. Not support before at this time.
69- // simple counter footer
70- ({ Text , Image }, context , current , total ) => {
71- // render in every page
72- Text (` ${current }/${total } ` , { fontSize: 20 }, {
73- x: context .width / 2 ,
74- y: context .height - context .margins .bottom
75- })
76-
77- // Image('https://i.imgur.com/to/path.png', {}, {})
78- },
79- // simple header
80- ({ Text }, context , current , total ) => {
81- // render in every page
82- Text (' A Simple Header' , {}, {
83- x: context .width / 2 ,
84- // negative number (-30 in case) ignore default margins
85- y: context .margins .top - 20
86- })
87- }
88- ]
89- }
90- ]
50+ }
9151})
9252
53+ pdfeasy .add ([
54+ { raw: ' Simple text!' },
55+ ])
56+
57+ pdfeasy .run ({
58+ type: ' client' ,
59+ clientEmit: ' blob'
60+ }).then ((blob : string ) => {
61+ const iframe = document .querySelector (' #pdf' ) as HTMLIFrameElement
62+
63+ iframe .src = blob
64+ }).catch ((err : any ) => {
65+ console .error (err )
66+ })
67+ ```
68+
69+ ## Content
70+
71+ ``` ts
9372pdfeasy .add ([
9473 ... Utils .content (), // Utils for debug
95- { raw: ' Hello PDFEasy!' , text: { font: ' Roboto' }}, // custom font,
74+ { raw: ' Hello PDFEasy!' , text: { font: ' Roboto' }}, // text with custom font,
9675 { raw: ' https://i.imgur.com/path.png' , image: {}}, // external image
9776 { stack: [ // stack for paragraph's
9877 { raw: ' A ' , text: {}},
9978 { raw: ' Simple' , text: { bold: true , italic: true }},
10079 { raw: ' Stack!' , text: {}},
10180 ]},
102- // not recommended use this
103- { raw: ' Text without option!' },
10481])
82+ ```
83+
84+ ## Plugins
10585
86+ ``` ts
87+ pdfeasy .new ({
88+ plugins: [{
89+ cover: ' https://i.imgur.com/path.png' , // cover image (it's ignore default explicit margins insert)
90+ background : (page ) => { // render custom background in pages
91+ return ' https://i.imgur.com/path.png'
92+ },
93+ onBefore : () => {
94+ // before contents transform
95+ },
96+ onAfter : () => {
97+ // after contents transform
98+ },
99+ page: [ // render callback in every page AFTER finish contents insert. Not support before at this time.
100+ // simple counter footer
101+ ({ Text , Image }, context , current , total ) => {
102+ // render in every page
103+ Text (` ${current }/${total } ` , { fontSize: 20 }, {
104+ x: context .width / 2 ,
105+ y: context .height - context .margins .bottom
106+ })
107+
108+ // Image('https://i.imgur.com/to/path.png', {}, {})
109+ },
110+ // simple header
111+ ({ Text }, context , current , total ) => {
112+ // render in every page
113+ Text (' A Simple Header' , {}, {
114+ x: context .width / 2 ,
115+ // negative number (-20 in case) ignore default pdfkit margins
116+ y: context .margins .top - 20
117+ })
118+ }
119+ ]
120+ }]
121+ })
122+ ```
123+
124+ > Plugins runs as a queue.
125+
126+ ## Runner Options
127+
128+ ``` ts
129+ pdfeasy .run ({
130+ type: ' client' ,
131+ clientEmit: ' save'
132+ }).then (() => {}).catch ((err : any ) => {
133+ console .error (err )
134+ })
135+ ```
136+
137+ ``` ts
138+ pdfeasy .run ({
139+ type: ' server' ,
140+ serverPath: path .resolve (process .cwd () + ' /examples' )
141+ }).then (() => {}).catch ((err : any ) => {
142+ console .error (err )
143+ })
144+ ```
145+
146+ ## Custom Fonts
147+
148+ ``` ts
106149// or https://path/to/Roboto.ttf
107150pdfeasy .addFonts ([
108151 {
@@ -113,15 +156,11 @@ pdfeasy.addFonts([
113156 bolditalic: ' fonts/Roboto-BoldItalic.ttf'
114157 }
115158])
159+ ```
116160
117- pdfeasy .run ().then ((blob : string ) => {
118- const iframe = document .querySelector (' #pdf' ) as HTMLIFrameElement
161+ > ** Attention!** Client-Side version not support relative/absolute font paths at this time.
119162
120- iframe .src = blob
121- }).catch ((err : any ) => {
122- console .error (err )
123- })
124- ```
163+ ## Resources
125164
126165See [ source demo] ( ./demo ) for more explanations
127166
@@ -131,7 +170,7 @@ See [scripts](./scripts/generate/) for server-side runner.
131170
132171## Bundles
133172
134- > Uses standard minification
173+ > ** Attention! ** Its recommended use explicit imports ( * import pdfeasy from 'pdfeasy/dist/client.esm.js' * ) in your projects.
135174
136175` pdfeasy/dist/client.cjs.js `
137176
@@ -142,5 +181,3 @@ See [scripts](./scripts/generate/) for server-side runner.
142181` pdfeasy/dist/node.esm.js `
143182
144183` pdfeasy/dist/node.iife.js `
145-
146- ` pdfeasy/dist/index.d.ts `
0 commit comments