jspdf
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@babel/runtime | 7.24.5 | 256.12 kB | MIT | prod optional | |
atob | 2.1.2 | 12.42 kB | (MIT OR Apache-2.0) | prod | |
btoa | 1.2.1 | 11.19 kB | (MIT OR Apache-2.0) | prod | |
canvg | 3.0.10 | 347.7 kB | MIT | prod optional | 2 |
core-js | 3.37.0 | 1.17 MB | MIT | prod optional | 1 |
dompurify | 2.5.2 | 727.92 kB | (MPL-2.0 OR Apache-2.0) | prod optional | |
fflate | 0.4.8 | 66.85 kB | MIT | prod | |
html2canvas | 1.4.1 | 604.93 kB | MIT | prod optional |
jsPDF is a widely recognized library that is utilized to generate PDFs using JavaScript. Enthusiastically adopted due to its powerful features, jsPDF enables developers to create complex PDF documents and gives them the ability to perform tasks such as adding text, changing the printing orientation, setting format and size parameters, and much more.
To use jsPDF, install it via npm or yarn with the commands npm install jspdf --save
or yarn add jspdf
. Additionally, jsPDF can be loaded from a CDN or using the latest version via unpkg.
Below showcases a basic example of how you can leverage the jsPDF library:
import { jsPDF } from "jspdf";
// Create a new PDF document
const doc = new jsPDF();
// Add text to the document
doc.text("Hello world!", 10, 10);
// Save the document with a specific filename
doc.save("a4.pdf");
For more complex PDF configurations, the library allows the alteration of paper size, orientation or units. For instance, to create a 2x4 inches landscape document:
// Initialize a new PDF document with specific parameters
const doc = new jsPDF({
orientation: "landscape",
unit: "in",
format: [4, 2]
});
// Add text to the document
doc.text("Hello world!", 1, 1);
// Save the document with a specific filename
doc.save("two-by-four.pdf");
The documentation for jsPDF, including various examples and detailed descriptions for each method, can be found at Documentation. The website houses a plethora of resources and guides that provide in-depth knowledge on how to effectively use the jsPDF library in your projects.