@pdfme/ui 4.5.2 → 5.0.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -11
- package/dist/index.es.js +534 -530
- package/dist/index.umd.js +14 -14
- package/dist/types/Form.d.ts +1 -1
- package/dist/types/class.d.ts +5 -2
- package/dist/types/components/Preview.d.ts +1 -1
- package/dist/types/helper.d.ts +4 -4
- package/package.json +2 -1
- package/src/Form.tsx +7 -7
- package/src/components/Designer/LeftSidebar.tsx +1 -1
- package/src/components/Designer/RightSidebar/DetailView/index.tsx +6 -6
- package/src/components/Designer/RightSidebar/ListView/SelectableSortableContainer.tsx +2 -2
- package/src/components/Designer/RightSidebar/ListView/SelectableSortableItem.tsx +3 -3
- package/src/components/Designer/RightSidebar/ListView/index.tsx +2 -2
- package/src/components/Designer/index.tsx +8 -8
- package/src/components/Preview.tsx +15 -11
- package/src/components/Renderer.tsx +1 -2
- package/src/helper.ts +56 -70
- package/src/hooks.ts +4 -4
- package/tsconfig.json +1 -1
package/README.md
CHANGED
@@ -27,6 +27,7 @@
|
|
27
27
|
|
28
28
|
<p align="center">TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!</p>
|
29
29
|
|
30
|
+
|
30
31
|
## Features
|
31
32
|
|
32
33
|
| Fast PDF Generator | Easy PDF template design | Simple JSON template |
|
@@ -70,6 +71,9 @@ npm i @pdfme/ui @pdfme/common
|
|
70
71
|
|
71
72
|
\*You must install `@pdfme/common` regardless of which package you use.
|
72
73
|
|
74
|
+
On NPM stable releases are published to the `latest` tag, and pre-releases are published to the `next` tag.
|
75
|
+
On the `dev` tag you can find releases for every commit to the `main` branch.
|
76
|
+
|
73
77
|
The following type, function and classes are available in pdfme.
|
74
78
|
|
75
79
|
`@pdfme/common`
|
@@ -117,9 +121,8 @@ The following image is a good illustration of a template.
|
|
117
121
|
**basePdf** can be given a `string`(base64), `ArrayBuffer`, or `Uint8Array`.
|
118
122
|
A blank A4 PDF can be imported with `BLANK_PDF`. You can use it to check how it works.
|
119
123
|
|
120
|
-
**
|
121
|
-
Additionally, you can create your own schemas, allowing you to render types other than the ones mentioned above.
|
122
|
-
Check detail about [Custom Schemas](https://pdfme.com/docs/custom-schemas) from here
|
124
|
+
**Schemas** can only utilize text by default, but you can load images and various barcodes like QR codes as plugins from the `@pdfme/schemas` package.
|
125
|
+
Additionally, you can create your own schemas, allowing you to render types other than the ones mentioned above. Check detail about [Custom Schemas](https://pdfme.com/docs/custom-schemas) from here.
|
123
126
|
|
124
127
|
Let's take a look at some specific data.
|
125
128
|
(If you are using TypeScript, you can import the Template type.)
|
@@ -132,26 +135,29 @@ import { Template, BLANK_PDF } from '@pdfme/common';
|
|
132
135
|
const template: Template = {
|
133
136
|
basePdf: BLANK_PDF,
|
134
137
|
schemas: [
|
135
|
-
|
136
|
-
|
138
|
+
[
|
139
|
+
{
|
140
|
+
name: 'a',
|
137
141
|
type: 'text',
|
138
142
|
position: { x: 0, y: 0 },
|
139
143
|
width: 10,
|
140
144
|
height: 10,
|
141
145
|
},
|
142
|
-
|
146
|
+
{
|
147
|
+
name: 'a',
|
143
148
|
type: 'text',
|
144
149
|
position: { x: 10, y: 10 },
|
145
150
|
width: 10,
|
146
151
|
height: 10,
|
147
152
|
},
|
148
|
-
|
153
|
+
{
|
154
|
+
name: 'c',
|
149
155
|
type: 'text',
|
150
156
|
position: { x: 20, y: 20 },
|
151
157
|
width: 10,
|
152
158
|
height: 10,
|
153
159
|
},
|
154
|
-
|
160
|
+
],
|
155
161
|
],
|
156
162
|
};
|
157
163
|
```
|
@@ -193,7 +199,7 @@ Also, each element in the inputs array corresponds to a page in the PDF, you can
|
|
193
199
|
|
194
200
|
## UI
|
195
201
|
|
196
|
-
The UI is composed of the Designer, Form, and Viewer classes.
|
202
|
+
The UI is composed of the [Designer](https://pdfme.com/docs/getting-started#designer), [Form](https://pdfme.com/docs/getting-started#form), and [Viewer](https://pdfme.com/docs/getting-started#viewer) classes.
|
197
203
|
|
198
204
|
### Designer
|
199
205
|
|
@@ -225,7 +231,6 @@ The designer instance can be manipulated with the following methods.
|
|
225
231
|
- `saveTemplate`
|
226
232
|
- `updateTemplate`
|
227
233
|
- `getTemplate`
|
228
|
-
- `getPageCursor`
|
229
234
|
- `onChangeTemplate`
|
230
235
|
- `onSaveTemplate`
|
231
236
|
- `destroy`
|
@@ -286,6 +291,72 @@ const viewer = new Viewer({ domContainer, template, inputs });
|
|
286
291
|
|
287
292
|

|
288
293
|
|
294
|
+
### Using additional schemas and custom plugins
|
295
|
+
|
296
|
+
The examples so far use only the `text` schema type. There are many others built-in within the `@pdfme/schemas` package, and you can use your own:
|
297
|
+
|
298
|
+
Here's an example using additional schemas from built-in and custom plugins:
|
299
|
+
|
300
|
+
```ts
|
301
|
+
import { Template, BLANK_PDF } from '@pdfme/common';
|
302
|
+
import { text, barcodes, image } from '@pdfme/schemas';
|
303
|
+
import myPlugin from './custom-plugins';
|
304
|
+
|
305
|
+
const template: Template = {
|
306
|
+
basePdf: BLANK_PDF,
|
307
|
+
schemas: [
|
308
|
+
[
|
309
|
+
{
|
310
|
+
name: 'example_text',
|
311
|
+
type: 'text',
|
312
|
+
position: { x: 0, y: 0 },
|
313
|
+
width: 40,
|
314
|
+
height: 10,
|
315
|
+
},
|
316
|
+
{
|
317
|
+
name: 'example_image',
|
318
|
+
type: 'image',
|
319
|
+
position: { x: 200, y: 200 },
|
320
|
+
width: 60,
|
321
|
+
height: 40,
|
322
|
+
},
|
323
|
+
{
|
324
|
+
name: 'example_qr_code',
|
325
|
+
type: 'qrcode',
|
326
|
+
position: { x: 100, y: 100 },
|
327
|
+
width: 50,
|
328
|
+
height: 50,
|
329
|
+
},
|
330
|
+
],
|
331
|
+
],
|
332
|
+
};
|
333
|
+
|
334
|
+
const plugins = {
|
335
|
+
Text: multiVariableText,
|
336
|
+
'QR Code': barcodes.qrcode,
|
337
|
+
Image: image,
|
338
|
+
MyPlugin: myPlugin
|
339
|
+
}
|
340
|
+
|
341
|
+
const inputs = [{
|
342
|
+
example_text: 'a1',
|
343
|
+
example_image: 'data:image/png;base64,iVBORw0KG....',
|
344
|
+
example_qr_code: 'https://pdfme.com/'
|
345
|
+
}];
|
346
|
+
|
347
|
+
generate({ template, inputs, plugins }).then((pdf) => {
|
348
|
+
console.log(pdf);
|
349
|
+
});
|
350
|
+
|
351
|
+
```
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
## Examples using pdfme
|
356
|
+
|
357
|
+
If you are looking for code examples using pdfme to get started, please check out the [pdfme-playground](https://github.com/pdfme/pdfme-playground) repository
|
358
|
+
or look at the examples in the `websit/src/pages/` folder of this repository. Settings these up is covered in the [DEVELOPMENT.md](DEVELOPMENT.md) file.
|
359
|
+
|
289
360
|
## Special Thanks
|
290
361
|
|
291
362
|
- [pdf-lib](https://pdf-lib.js.org/): Used in PDF generation.
|
@@ -297,7 +368,7 @@ const viewer = new Viewer({ domContainer, template, inputs });
|
|
297
368
|
- [react-moveable](https://daybrush.com/moveable/), [react-selecto](https://github.com/daybrush/selecto), [@scena/react-guides](https://daybrush.com/guides/): Used in Designer UI.
|
298
369
|
- [dnd-kit](https://github.com/clauderic/dnd-kit): Used in Designer UI.
|
299
370
|
|
300
|
-
|
371
|
+
I definitely could not have created pdfme without these libraries. I am grateful to the developers of these libraries.
|
301
372
|
|
302
373
|
If you want to contribute to pdfme, please check the [Development Guide](https://pdfme.com/docs/development-guide) page.
|
303
374
|
We look forward to your contribution!
|