What is @syncfusion/ej2-pdf-export?
@syncfusion/ej2-pdf-export is a comprehensive library for creating and manipulating PDF documents in JavaScript. It provides a wide range of functionalities including text, image, and table insertion, as well as support for various PDF features like annotations, bookmarks, and form fields.
What are @syncfusion/ej2-pdf-export's main functionalities?
Create a PDF Document
This feature allows you to create a new PDF document, add a page to it, and draw text on the page. The document is then saved as 'output.pdf'.
const { PdfDocument, PdfPage, PdfGraphics, PdfTextElement } = require('@syncfusion/ej2-pdf-export');
let document = new PdfDocument();
let page = document.pages.add();
let graphics = page.graphics;
let textElement = new PdfTextElement('Hello, World!');
textElement.draw(graphics, { x: 10, y: 10 });
document.save('output.pdf');
document.destroy();
Add Images to PDF
This feature allows you to add images to a PDF document. The image is drawn on the specified coordinates on the page.
const { PdfDocument, PdfPage, PdfGraphics, PdfBitmap } = require('@syncfusion/ej2-pdf-export');
let document = new PdfDocument();
let page = document.pages.add();
let graphics = page.graphics;
let image = new PdfBitmap('path/to/image.jpg');
graphics.drawImage(image, { x: 10, y: 10, width: 100, height: 100 });
document.save('output_with_image.pdf');
document.destroy();
Create Tables in PDF
This feature allows you to create tables within a PDF document. You can define the number of columns and rows, and set the values for each cell.
const { PdfDocument, PdfPage, PdfGrid } = require('@syncfusion/ej2-pdf-export');
let document = new PdfDocument();
let page = document.pages.add();
let grid = new PdfGrid();
grid.columns.add(3);
grid.headers.add(1);
let header = grid.headers.getHeader(0);
header.cells.getCell(0).value = 'Column 1';
header.cells.getCell(1).value = 'Column 2';
header.cells.getCell(2).value = 'Column 3';
let row = grid.rows.addRow();
row.cells.getCell(0).value = 'Row 1, Cell 1';
row.cells.getCell(1).value = 'Row 1, Cell 2';
row.cells.getCell(2).value = 'Row 1, Cell 3';
grid.draw(page, { x: 10, y: 10 });
document.save('output_with_table.pdf');
document.destroy();
Other packages similar to @syncfusion/ej2-pdf-export
pdf-lib
pdf-lib is a popular library for creating and modifying PDF documents in JavaScript. It offers a wide range of functionalities similar to @syncfusion/ej2-pdf-export, such as text and image insertion, form field creation, and more. However, pdf-lib is known for its simplicity and ease of use, making it a good choice for developers looking for a straightforward solution.
jspdf
jspdf is another widely-used library for generating PDF documents in JavaScript. It provides functionalities for adding text, images, and shapes to PDF documents. Compared to @syncfusion/ej2-pdf-export, jspdf is more lightweight and has a larger community, but it may lack some of the advanced features and optimizations found in @syncfusion/ej2-pdf-export.
pdfmake
pdfmake is a powerful library for creating PDF documents in JavaScript. It offers a declarative syntax for defining the content and layout of PDF documents. While pdfmake provides a high level of customization and flexibility, it may have a steeper learning curve compared to @syncfusion/ej2-pdf-export.
Overview
PDF is a modern JavaScript library used to create PDF documents.
It is written in TypeScript and has no external dependencies.
Key Features
The following list shows the key features available in PDF library.
- Creating PDF from scratch.
- Adding text.
- Rendering JPEG images.
- Drawing tables.
- Drawing lines and rectangles.