Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jspdf

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jspdf

PDF Document creation from JavaScript

  • 2.5.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6M
increased by6.72%
Maintainers
1
Weekly downloads
 
Created

What is jspdf?

The jsPDF npm package is a library that allows you to generate PDF documents using JavaScript. It can be used in a web browser or in a server-side environment using Node.js. It provides a wide range of features to create and manipulate PDF documents programmatically.

What are jspdf's main functionalities?

Text

This feature allows you to add text to a PDF document. The code sample demonstrates how to create a PDF with the text 'Hello world!' at coordinates (10, 10) on the page.

const { jsPDF } = require('jspdf');
const doc = new jsPDF();
doc.text('Hello world!', 10, 10);
doc.save('hello_world.pdf');

Graphics

This feature allows you to draw shapes and graphics, such as rectangles, circles, and lines. The code sample shows how to draw a filled red rectangle with a black border.

const { jsPDF } = require('jspdf');
const doc = new jsPDF();
doc.setDrawColor(0);
doc.setFillColor(255, 0, 0);
doc.rect(20, 20, 10, 10, 'FD');
doc.save('rectangle.pdf');

Images

This feature allows you to embed images into a PDF. The code sample demonstrates adding an image to the PDF, specifying the format, position, and size of the image.

const { jsPDF } = require('jspdf');
const doc = new jsPDF();
// Image must be in base64 format or a URL
const imgData = 'data:image/jpeg;base64,...';
doc.addImage(imgData, 'JPEG', 15, 40, 180, 160);
doc.save('image.pdf');

Fonts and Styles

This feature allows you to customize the font and style of the text in the PDF. The code sample sets the font to Helvetica, makes it bold, sets the font size, and then adds the text to the document.

const { jsPDF } = require('jspdf');
const doc = new jsPDF();
doc.setFont('helvetica', 'bold');
doc.setFontSize(16);
doc.text('Styled text', 10, 20);
doc.save('styled_text.pdf');

Vector Graphics

This feature allows you to create vector graphics such as lines and curves. The code sample draws a line with a certain width on the PDF.

const { jsPDF } = require('jspdf');
const doc = new jsPDF();
doc.setLineWidth(0.5);
doc.line(20, 20, 60, 20);
doc.save('line.pdf');

Other packages similar to jspdf

Keywords

FAQs

Package last updated on 17 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc