pdfme
Open-source PDF generation library built with TypeScript and React. Features a WYSIWYG template designer, PDF viewer, and powerful generation capabilities. Create custom PDFs effortlessly in both browser and Node.js environments.
Top Related Projects
Quick Overview
PDFme is a JavaScript library for creating and editing PDF documents in the browser or Node.js environment. It provides a user-friendly API for generating PDFs from templates, filling forms, and manipulating existing PDF files without requiring server-side processing.
Pros
- Cross-platform compatibility (works in browsers and Node.js)
- Lightweight and easy to use
- Supports both creating new PDFs and editing existing ones
- Offers a visual template designer for easy PDF layout creation
Cons
- Limited advanced PDF features compared to some server-side libraries
- Performance may be slower for large or complex PDFs in browser environments
- Documentation could be more comprehensive for advanced use cases
Code Examples
Creating a simple PDF:
import { generate } from '@pdfme/generator';
const template = {
basePdf: { width: 595, height: 842 },
schemas: [
{
name: { type: 'text', position: { x: 20, y: 20 } },
age: { type: 'text', position: { x: 20, y: 40 } },
},
],
};
const inputs = [
{ name: 'John Doe', age: '30' },
];
generate({ template, inputs }).then((pdf) => {
// Use the generated PDF
});
Filling a PDF form:
import { generate } from '@pdfme/generator';
const template = {
basePdf: 'path/to/form.pdf',
schemas: [
{
name: { type: 'text', fieldName: 'Name' },
email: { type: 'text', fieldName: 'Email' },
},
],
};
const inputs = [
{ name: 'Jane Smith', email: 'jane@example.com' },
];
generate({ template, inputs }).then((pdf) => {
// Use the filled PDF
});
Adding an image to a PDF:
import { generate } from '@pdfme/generator';
const template = {
basePdf: { width: 595, height: 842 },
schemas: [
{
logo: { type: 'image', position: { x: 20, y: 20, width: 100, height: 100 } },
},
],
};
const inputs = [
{ logo: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==' },
];
generate({ template, inputs }).then((pdf) => {
// Use the PDF with the added image
});
Getting Started
-
Install PDFme:
npm install @pdfme/generator
-
Import and use in your project:
import { generate } from '@pdfme/generator'; const template = { basePdf: { width: 595, height: 842 }, schemas: [ { text: { type: 'text', position: { x: 20, y: 20 } }, }, ], }; const inputs = [{ text: 'Hello, PDFme!' }]; generate({ template, inputs }).then((pdf) => { // Use the generated PDF (e.g., save to file or display in browser) });
Competitor Comparisons
📄 Create PDF files using React
Pros of react-pdf
- More comprehensive and feature-rich for creating complex PDF documents
- Better integration with React applications
- Larger community and more frequent updates
Cons of react-pdf
- Steeper learning curve due to its complexity
- Larger bundle size, which may impact performance in some applications
Code Comparison
react-pdf:
import { Document, Page, Text, View, StyleSheet } from '@react-pdf/renderer';
const MyDocument = () => (
<Document>
<Page>
<View>
<Text>Hello, World!</Text>
</View>
</Page>
</Document>
);
pdfme:
import { Template, Form } from '@pdfme/generator';
const template = {
basePdf: { ... },
schemas: [{ ... }]
};
const form = new Form(template);
form.generate({ ... });
Summary
react-pdf is a more comprehensive solution for creating complex PDF documents, especially in React applications. It offers a wider range of features and has a larger community. However, it comes with a steeper learning curve and larger bundle size. pdfme, on the other hand, provides a simpler API for basic PDF generation tasks, which may be sufficient for less complex use cases. The choice between the two depends on the specific requirements of your project and your familiarity with React.
A JavaScript PDF generation library for Node and the browser
Pros of PDFKit
- More mature and established project with a larger community
- Extensive documentation and examples available
- Supports a wider range of PDF features and customization options
Cons of PDFKit
- Steeper learning curve for beginners
- Requires more code to create simple PDFs
- Less focus on form filling and template-based PDF generation
Code Comparison
PDFKit:
const PDFDocument = require('pdfkit');
const doc = new PDFDocument();
doc.pipe(fs.createWriteStream('output.pdf'));
doc.text('Hello, world!');
doc.end();
PDFMe:
import { Template } from '@pdfme/generator';
const template = new Template({ schemas: [...], basePdf: [...] });
const inputs = [{ name: 'John Doe', age: '30' }];
const pdf = await template.generate({ inputs });
Key Differences
- PDFKit offers more low-level control over PDF creation
- PDFMe focuses on template-based generation and form filling
- PDFKit has a larger ecosystem and more third-party plugins
- PDFMe provides a simpler API for basic PDF generation tasks
Use Cases
- Choose PDFKit for complex, highly customized PDF documents
- Opt for PDFMe when working with form-based PDFs or simple templates
- PDFKit is better suited for server-side PDF generation
- PDFMe excels in client-side PDF creation and form filling scenarios
Client/server side PDF printing in pure JavaScript
Pros of pdfmake
- More mature and established project with a larger community
- Extensive documentation and examples available
- Supports complex layouts and styling options
Cons of pdfmake
- Steeper learning curve due to more complex API
- Larger file size and potentially slower performance for simple documents
Code Comparison
pdfmake:
var docDefinition = {
content: [
'First paragraph',
'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
]
};
pdfMake.createPdf(docDefinition).download();
pdfme:
import { Template, generate } from '@pdfme/generator';
const template = {
basePdf: { width: 595, height: 842 },
schemas: [{ text: { type: 'text', position: { x: 0, y: 0 } } }],
};
const inputs = [{ text: 'Hello World' }];
generate({ template, inputs }).then((pdf) => {
pdf.download();
});
Summary
pdfmake offers more advanced features and extensive documentation, making it suitable for complex PDF generation tasks. However, it may have a steeper learning curve and larger file size. pdfme provides a simpler API and potentially better performance for basic documents, but may lack some advanced features found in pdfmake. The choice between the two depends on the specific requirements of your project and the complexity of the PDFs you need to generate.
PDF Reader in JavaScript
Pros of pdf.js
- Widely adopted and battle-tested in production environments
- Extensive browser compatibility, including older versions
- Robust feature set for rendering and interacting with PDFs
Cons of pdf.js
- Larger file size and potentially higher resource usage
- Steeper learning curve for implementation and customization
- Primarily focused on rendering, less suited for PDF creation or editing
Code Comparison
pdf.js:
pdfjsLib.getDocument('https://example.com/sample.pdf').promise.then(function(pdf) {
pdf.getPage(1).then(function(page) {
var scale = 1.5;
var viewport = page.getViewport({ scale: scale });
// Render page on canvas
});
});
pdfme:
import { Template, Form } from '@pdfme/ui';
const template = new Template(templateDefinition);
const form = new Form({ template, inputs });
form.render(document.getElementById('container'));
Key Differences
- pdf.js focuses on rendering and viewing PDFs, while pdfme specializes in PDF form creation and filling
- pdf.js offers more low-level control over PDF rendering, whereas pdfme provides a higher-level API for form-based operations
- pdfme has a smaller footprint and is more suitable for specific PDF form tasks, while pdf.js is a more comprehensive PDF solution
Client-side JavaScript PDF generation for everyone.
Pros of jsPDF
- More mature and widely adopted project with a larger community
- Supports a broader range of PDF features and functionalities
- Better documentation and examples available
Cons of jsPDF
- Larger file size and potentially slower performance
- Steeper learning curve for complex PDF generation tasks
- Less focus on template-based PDF creation
Code Comparison
pdfme:
import { Template, generate } from '@pdfme/generator';
const template = {
basePdf: BASE64_PDF_TEMPLATE,
schemas: [
{
name: { type: 'text', position: { x: 20, y: 20 } },
},
],
};
const inputs = [{ name: 'John Doe' }];
const pdf = await generate({ template, inputs });
jsPDF:
import { jsPDF } from "jspdf";
const doc = new jsPDF();
doc.text("Hello world!", 10, 10);
doc.addPage();
doc.text("This is a new page", 10, 10);
doc.save("a4.pdf");
Both libraries offer PDF generation capabilities, but pdfme focuses on template-based creation, while jsPDF provides more low-level control over PDF content. pdfme is easier to use for simple template-based PDFs, while jsPDF offers more flexibility for complex PDF generation tasks.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
PDFME
Website | pdfme Cloud | Discord
TypeScript-based PDF generator and React-based UI. Open source, developed by the community, and completely free to use under the MIT license!
Features
Fast PDF Generator | Easy PDF Template Design | Simple JSON Template |
---|---|---|
Works on Node and in the browser. Use templates to generate PDFsâcomplex operations are not required. | Anyone can easily create templates using the designer. | Templates are JSON data that is easy to understand and work with. |
Custom Feature Requests
While pdfme is an open-source project released under the MIT License, we are open to considering custom feature additions for a fee.
If you are willing to pay, we can evaluate and implement your requested features.
Please note that any additional functionality will always be released as open source. If this approach works for you, please contact us.
For a detailed list of supported features, please refer to the Supported Features page.
Documentation
For complete documentation on pdfme, please refer to the Getting Started guide.
Examples Using pdfme
If you're looking for code examples to get started with pdfme, check out the pdfme-playground website and the playground source code. Setup instructions can be found in the DEVELOPMENT.md file.
Cloud Service Option
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 hassle of 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:
- PDF generation at scale without infrastructure management
- Hosted WYSIWYG template designer
- Simple API integration
- Automatic updates and maintenance
pdfme will always remain open source. The cloud service is an optional offering for those who prefer a managed solution.
Sponsors
Support this project by becoming a sponsor. Your logo will appear here with a link to your website.
![]() | ||
---|---|---|
ProgressLab | PhotoQuest | New Sponsor |
Contributors
Special Thanks
- pdf-lib: Used for PDF generation.
- fontkit: Used for font rendering.
- PDF.js: Used for PDF viewing.
- React: Used in building the UI.
- form-render: Used in building the UI.
- antd: Used in building the UI.
- react-moveable, react-selecto, @scena/react-guides: Used in the Designer UI.
- dnd-kit: Used in the Designer UI.
- Lucide: Used in the Designer UI and Schema's icon.
I definitely could not have created pdfme without these libraries. I am grateful to the developers of these projects.
If you want to contribute to pdfme, please refer to the Development Guide.
We look forward to your contributions!
Top Related Projects
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot