Gathering detailed insights and metrics for @dsapdfmecustom542/root
Gathering detailed insights and metrics for @dsapdfmecustom542/root
Gathering detailed insights and metrics for @dsapdfmecustom542/root
Gathering detailed insights and metrics for @dsapdfmecustom542/root
npm install @dsapdfmecustom542/root
Typescript
Module System
Node Version
NPM Version
TypeScript (98.78%)
JavaScript (0.85%)
CSS (0.19%)
Shell (0.16%)
HTML (0.03%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
758 Commits
1 Watchers
1 Branches
32 Contributors
Updated on Nov 22, 2024
Latest Version
0.0.1
Package Id
@dsapdfmecustom542/root@0.0.1
Unpacked Size
100.78 MB
Size
74.06 MB
File Count
442
NPM Version
10.5.0
Node Version
20.12.2
Published on
Nov 21, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!
Fast PDF Generator | Easy PDF template design | Simple JSON template |
---|---|---|
Works on node and browser. Use templates to generate PDF, Complex operations are not needed. | Anyone can easily create templates with the designer. | Templates are JSON data that is easy to understand and handle. |
pdfme was created to simplify the design and generation process of a PDF. It is especially useful for the following use cases:
As an example, the author's service https://labelmake.jp/ can create more than 100 varieties of PDFs and generates more than 100,000 PDF files per month. Notably, the monthly server cost, utilizing Cloud Functions For Firebase, remains below $10.
The operating requirements should be the node environment >=16
.
There are two packages in pdfme, generator and UI.
The package for generating PDF can be installed with the following command.
npm i @pdfme/generator @pdfme/common
The packages for using PDF designer, forms and viewers can be installed with the following commands.
npm i @pdfme/ui @pdfme/common
*You must install @pdfme/common
regardless of which package you use.
On NPM stable releases are published to the latest
tag, and pre-releases are published to the next
tag.
On the dev
tag you can find releases for every commit to the main
branch.
The following type, function and classes are available in pdfme.
@pdfme/common
@pdfme/generator
@pdfme/ui
If your environment uses webpack, import the necessary items as shown below.
1import type { Template } from '@pdfme/common'; 2import { generate } from '@pdfme/generator';
1import type { Template } from '@pdfme/common'; 2import { Designer, Form, Viewer } from '@pdfme/ui';
All objects use Template
, which will be briefly explained in the next section.
The core of pdfme library are Templates.
Template Type can be imported by both @pdfme/generator
or @pdfme/ui
. Templates are used everywhere.
A template can be divided into two parts: a fixed part and a variable part.
We call them basePdf and schema.
The following image is a good illustration of a template.
basePdf can be given a string
(base64), ArrayBuffer
, or Uint8Array
.
A blank A4 PDF can be imported with BLANK_PDF
. You can use it to check how it works.
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.
Additionally, you can create your own schemas, allowing you to render types other than the ones mentioned above. Check detail about Custom Schemas from here.
Let's take a look at some specific data.
(If you are using TypeScript, you can import the Template type.)
1import { Template, BLANK_PDF } from '@pdfme/common'; 2 3const template: Template = { 4 basePdf: BLANK_PDF, 5 schemas: [ 6 [ 7 { 8 name: 'a', 9 type: 'text', 10 position: { x: 0, y: 0 }, 11 width: 10, 12 height: 10, 13 }, 14 { 15 name: 'a', 16 type: 'text', 17 position: { x: 10, y: 10 }, 18 width: 10, 19 height: 10, 20 }, 21 { 22 name: 'c', 23 type: 'text', 24 position: { x: 20, y: 20 }, 25 width: 10, 26 height: 10, 27 }, 28 ], 29 ], 30};
You can create a template from Template Design page. Or, if you want to integrate the template creation feature into your application, check out the Designer section.
The PDF generator function, generate
, takes 2 arguments of template
and inputs
for generate a PDF. It works both in Node.js and in the browser.
The code to generate a PDF file using the template created above is shown below.
1import type { Template } from '@pdfme/common'; 2import { generate } from '@pdfme/generator'; 3 4const template: Template = { 5 // skip... Check the Template section. 6}; 7const inputs = [{ a: 'a1', b: 'b1', c: 'c1' }]; 8 9generate({ template, inputs }).then((pdf) => { 10 console.log(pdf); 11 12 // Browser 13 // const blob = new Blob([pdf.buffer], { type: 'application/pdf' }); 14 // window.open(URL.createObjectURL(blob)); 15 16 // Node.js 17 // fs.writeFileSync(path.join(__dirname, `test.pdf`), pdf); 18});
You can create a PDF file like the below.
Also, each element in the inputs array corresponds to a page in the PDF, you can create a multi-page PDF file by providing multiple elements of inputs.
The UI is composed of the Designer, Form, and Viewer classes.
The Designer allows you to edit the Template schemas, making it easy for anyone to create Template json objects.
You can design your own template from Template Design page, or you can integrate the designer into your application.
Let's integrate the designer using the template created above as the default template.
1import type { Template } from '@pdfme/common'; 2import { Designer } from '@pdfme/ui'; 3 4const domContainer = document.getElementById('container'); 5const template: Template = { 6 // skip... Check the Template section. 7}; 8 9const designer = new Designer({ domContainer, template });
The Designer class is instantiated as shown above, and the template designer is displayed in the domContainer
.
You can edit the template as shown below. The operation is like Google Slides, etc., so you can use common keyboard shortcuts.
The designer instance can be manipulated with the following methods.
saveTemplate
updateTemplate
getTemplate
onChangeTemplate
onSaveTemplate
destroy
You can use templates to create forms and PDF viewers.
The Form creates a UI for the user to enter schemas based on the template.
1import type { Template } from '@pdfme/common'; 2import { Form } from '@pdfme/ui'; 3 4const domContainer = document.getElementById('container'); 5const template: Template = { 6 // skip... 7}; 8// This is initial data. 9const inputs = [{ a: 'a1', b: 'b1', c: 'c1' }]; 10 11const form = new Form({ domContainer, template, inputs });
The form instance has a method getInputs
to get the user's input.
You can generate a PDF file based on the user's input by passing the data you get from getInputs
as inputs to generate, as shown in the code below.
1generate({ template, inputs: form.getInputs() }).then((pdf) => {
2 const blob = new Blob([pdf.buffer], { type: 'application/pdf' });
3 window.open(URL.createObjectURL(blob));
4});
Viewing a PDF file in a mobile browser is a pain, because it doesn't display well in an iframe.
The Viewer is a byproduct of the Form development process, but it allows you to show your users a preview of the PDF file you will create.
Using the Viewer is basically the same as using the Form, except that user cannot edit it.
1import type { Template } from '@pdfme/common'; 2import { Viewer } from '@pdfme/ui'; 3 4const domContainer = document.getElementById('container'); 5const template: Template = { 6 // skip... 7}; 8const inputs = [{ a: 'a1', b: 'b1', c: 'c1' }]; 9 10const viewer = new Viewer({ domContainer, template, inputs });
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:
Here's an example using additional schemas from built-in and custom plugins:
1import { Template, BLANK_PDF } from '@pdfme/common'; 2import { text, barcodes, image } from '@pdfme/schemas'; 3import myPlugin from './custom-plugins'; 4 5const template: Template = { 6 basePdf: BLANK_PDF, 7 schemas: [ 8 [ 9 { 10 name: 'example_text', 11 type: 'text', 12 position: { x: 0, y: 0 }, 13 width: 40, 14 height: 10, 15 }, 16 { 17 name: 'example_image', 18 type: 'image', 19 position: { x: 200, y: 200 }, 20 width: 60, 21 height: 40, 22 }, 23 { 24 name: 'example_qr_code', 25 type: 'qrcode', 26 position: { x: 100, y: 100 }, 27 width: 50, 28 height: 50, 29 }, 30 ], 31 ], 32}; 33 34const plugins = { 35 Text: multiVariableText, 36 'QR Code': barcodes.qrcode, 37 Image: image, 38 MyPlugin: myPlugin 39} 40 41const inputs = [{ 42 example_text: 'a1', 43 example_image: 'data:image/png;base64,iVBORw0KG....', 44 example_qr_code: 'https://pdfme.com/' 45}]; 46 47generate({ template, inputs, plugins }).then((pdf) => { 48 console.log(pdf); 49}); 50
If you are looking for code examples using pdfme to get started, please check out the pdfme-playground repository
or look at the examples in the websit/src/pages/
folder of this repository. Settings these up is covered in the DEVELOPMENT.md file.
I definitely could not have created pdfme without these libraries. I am grateful to the developers of these libraries.
If you want to contribute to pdfme, please check the Development Guide page.
We look forward to your contribution!
While pdfme is a powerful open-source library, we understand that some users might prefer a managed solution. For those looking for a ready-to-use, scalable PDF generation service without the need for setup and maintenance, we offer pdfme Cloud.
Try pdfme Cloud - Hassle-free PDF Generation
pdfme Cloud provides all the features of the open-source library, plus:
*pdfme is and will always remain open-source. The cloud service is an optional offering for those who prefer a managed solution.
No vulnerabilities found.
No security vulnerabilities found.