Open Source JavaScript PDF Annotation Library

Free & Open Source JavaScript library for adding annotations to PDF documents.

What is PDFKit?

PDFKit is a free and open source JavaScript library for adding annotations such as links, crossed-out text and interactive notes to PDF files. An important point to note is: PDFKit doesn't allow opening or editing existing PDF documents so, you cannot add annotations to existing PDF documents however you can create PDF files from scratch using PDFKit library and then add annotations to them.

Following are some of the main annotation features of PDFKit:

  • Adding Links: PDFKit enables you to include clickable links within your PDF documents.
  • Adding Crossed-Out Text: You can apply a strikeout effect to text in your PDFs generated with PDFKit.
  • Adding Notes: PDFKit allows you to insert interactive note annotations into your PDF documents.
GitHub

GitHub Stats

Name:
Language:
Stars:
Forks:
License:
Repository was last updated at

Getting Started with PDFKit

You can install PDFKit library using the npm package manager. Just type the following command after installing npm.

Install using NPM


npm install pdfkit

Add Link Annotation to PDF

We can add hyperlinks in PDF documents using the link annotation feature of the PDFKit library. We provide the X and Y coordinates, as well as the height and width of the text, along with the link to make it a hyperlink using the link function as demonstrated in below code snippet:

Output

The following output displays the PDF document containing the hyperlink:

Add Crossed-Out Text to PDF

We can add crossed-out text to a PDF document using the moveTo and lineTo functions provided by the PDFKit library. The moveTo function positions the cursor at the starting point of the line, and the lineTo function is used to draw a line from that starting point to the end of the text to be crossed out. Check below code snippet for the details:

Output

The output screenshot displays the PDF document with the strike-out text added to it.

Add Interactive Notes to PDF

We can add interactive notes to our PDF documents, making them more engaging for readers. These interactive notes are displayed as icons within the PDF, and when users hover over them, they reveal pop-up content. You have full control over their placement and dimensions, adjusting the X, Y coordinates, height and width as needed. Try below code snippet to add an interactive note to the PDF:

Output

The following screenshot shows the PDF document with the interactive note added to it:

And when we hover over the yellow icon the complete note is displayed as below:

Conclusion

In conclusion, PDFKit is a free JavaScript library for adding annotations to PDF documents. It provides an accessible and user-friendly way to add annotations.

While PDFKit excels in many areas, it's important to note that the goTo function does not work as expected. Additionally, the note function may introduce extra spaces in the content, which can lead to undesired results. Moreover, as already mentioned earlier, we can add annotations to only new PDF documents (and not the existing PDFs) created with PDFKit. These inconsistencies may raise questions about its suitability for automated tasks. However, PDFKit remains a valuable tool for manual annotation and document customization.

Similar Products

 English