DEV Community

Cover image for How to Implement PDF Annotations in React for Seamless Document Review
Lucy Muturi for Syncfusion, Inc.

Posted on • Originally published at syncfusion.com on

How to Implement PDF Annotations in React for Seamless Document Review

TL;DR: Managing PDF reviews in React applications can be frustrating without built-in annotation tools, as users lack the ability to highlight, comment, or mark up documents directly in the browser. React PDF annotation solves this challenge by enabling interactive markup within a PDF Viewer, allowing developers to easily add, edit, and manage annotations through both UI and programmatic options.

What are PDF annotations?

Annotations in PDFs are user-added markups, such as highlights, underlines, strikethroughs, stamps, comments, free text, ink, and shapes, that make content clearer and easier to review.

Why PDF annotation matters

In real-world scenarios, reviewing PDFs without annotation tools often leads to inefficient workflows. Users typically rely on external communication channels to share feedback, which slows down decision-making and increases the risk of miscommunication.

How PDF Annotation Solves This

React PDF annotation enables users to add these markups directly inside the document, streamlining the review process and making it faster, more accurate, and highly contextual. This approach is especially useful for adding annotations online without relying on desktop tools.

In this blog, we’ll show you how to implement React PDF annotation using Syncfusion’s PDF Viewer. You will learn how to add PDF annotations through both the user interface and code, and how to integrate these features into your React applications for a seamless user experience.

Types of PDF annotations

When implementing React PDF annotation, you can add various annotation types to make documents interactive and easy to review. These annotations help users provide feedback, highlight important sections, and add context directly within the document:

1. Text markup annotation

Text markup annotations visually emphasize parts of a PDF without changing its original content. Common types include:

  • Highlight: Draw attention to key text
  • Underline: Indicate important phrases
  • Strikethrough: Mark deletions or outdated content
  • Squiggly: Flag areas needing review or correction

Text markup annotations in PDFs using JavaScript PDF Viewer


Text markup annotations in PDFs using JavaScript PDF Viewer

These annotations are commonly applied during legal document reviews, academic proofreading, and technical documentation processes to highlight important sections or suggest edits.

2. Shape annotation

The React PDF Viewer lets you add shape annotations like Rectangle, Circle, Arrow, Polygon, and Line to highlight specific areas in a document. These annotations are useful for marking and technical drawings, as well as for visually emphasizing sections.

Shape annotations in PDFs


Shape annotations in PDFs

They are particularly useful in design and technical documents where visual emphasis or marking diagrams is required.

3. Stamp annotation

Stamp annotations enable users to place predefined Dynamic, Sign Here, Standards, or custom stamps, such as “Approved” or “Rejected”, or logos, on a PDF to indicate status or branding.

Stamp annotation in PDFs


Stamp annotation in PDFs

These annotations are commonly used in workflows to confirm approvals or indicate document status.

4. Sticky notes

Sticky notes enable users to add small comment pop-ups to a PDF, offering feedback or extra context without cluttering the main content.

Sticky notes in PDFs


Sticky notes in PDFs

They are ideal for document reviews where suggestions or clarifications need to be added inline.

5. Free text annotation

Free Text annotations enable users to type text directly onto the PDF, adding visible notes or instructions without modifying the original content.

Free text annotation in PDFs


Free text annotation in PDFs

This is useful for adding comments, labels, or instructions in forms and review documents.

6. Ink annotation

Ink annotations enable users to draw freehand on a PDF using a pen tool, making them perfect for sketches, notes, or signatures.

Ink annotation in PDFs


Ink annotation in PDFs

They are commonly used to sign forms, mark diagrams, or add any freehand input.

7. Measurement annotation

Measurement annotations enable users to measure distances, radii, volume, or areas directly on a PDF, which is particularly useful for precision-based tasks.

Measurement annotation in PDFs


Measurement annotation in PDFs

This is essential for precision-based tasks such as architectural plans and engineering drawings.

8. Handwritten signature

The React PDF Viewer supports handwritten signature annotations, allowing users to sign documents directly in the browser.

Handwritten signature annotations in PDFs


Handwritten signature annotations in PDFs

This is essential for precision-based tasks such as architectural plans and engineering drawings.

If you want to try these annotations in your application, check out the live React PDF annotation demo and explore the official documentation to learn how interactive markups work in a PDF Viewer.

Now that we’ve explored the various annotation types, let’s move on to the steps for integrating the Syncfusion React PDF Viewer into your application so you can begin adding annotations to your PDFs.

Install Syncfusion React PDF Viewer to add PDF annotation

To set up the Syncfusion PDF Viewer in your application, follow these steps:

Step 1: Install the Syncfusion PDF Viewer Library

Begin by installing the Syncfusion PDF Viewer package using npm. This library provides all the modules required to render PDFs and enable annotation features in your React application:

npm install @syncfusion/ej2-react-pdfviewer --save
Enter fullscreen mode Exit fullscreen mode

Step 2: Import required modules

After installation, import the PdfViewerComponent along with other modules that support features such as toolbar, magnification, navigation, annotation, link annotation, thumbnail view, bookmark view, text selection, text search, form fields, and form designer:

import { 
    PdfViewerComponent,
    Toolbar,
    Magnification,
    Navigation,
    Annotation,
    LinkAnnotation,
    ThumbnailView,
    BookmarkView,
    TextSelection,
    TextSearch,
    FormFields,
    FormDesigner 
} from '@syncfusion/ej2-react-pdfviewer';
Enter fullscreen mode Exit fullscreen mode

Step 3: Initialize the viewer

Add the PdfViewerComponent to your React application and configure its properties. Specify the document path, set the height, and provide the service URL for backend processing.

<PdfViewerComponent
    id="pdfViewer"
    documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
    style={{ height: '640px' }}
    serviceUrl="https://services.syncfusion.com/react/production/api/pdfviewer" >
</PdfViewerComponent>
Enter fullscreen mode Exit fullscreen mode

Note: For a detailed walkthrough, refer to the official documentation.

Once the PDF Viewer is set up, you can start adding, removing, and organizing annotations using the integrated toolbar or programmatically through APIs.

Adding PDF annotations

Adding annotations becomes simple with Syncfusion’s built-in tools and APIs.

1. Add Annotations via the UI

Users can add highlights, shapes, stamps, ink, free text, sticky notes, and signatures using the toolbar. The intuitive interface allows direct interaction with annotations on PDF pages.

Add PDF annotations in JavaScript


Add PDF annotations in JavaScript

2. Add annotations programmatically

For developers seeking flexibility and automation, the API provides a powerful way to dynamically add annotations. Instead of relying on the UI, you can use the addAnnotation method to create annotations programmatically:

pdfviewer.annotation.addAnnotation(type, options);
Enter fullscreen mode Exit fullscreen mode
  • type: Annotation type, such as Highlight, StickyNotes, or Line.
  • options: Defines properties like position, size, color, and page number.

Note: For more details on adding annotations, refer to the official documentation.

Deleting PDF annotations

Removing annotations is as straightforward as adding them. You can delete annotations either through the user interface or programmatically using Syncfusion’s React PDF Viewer.

1. Delete via UI

Users can quickly remove annotations by clicking the Delete icon in the toolbar or by right-clicking the annotation and selecting Delete from the context menu. This provides an easy and intuitive way to clean up unwanted markups during review.

Delete PDF annotations in React PDF Viewer


Delete PDF annotations in React PDF Viewer

2. Delete programmatically

For developers who need more control, annotations can be deleted programmatically using the deleteAnnotationById method. Pass the annotation’s unique ID as shown below:

viewer.annotationModule.deleteAnnotationById(annotationId); 
// annotationId is a unique ID of the annotation, and it can be retrieved from the annotationCollection array.
Enter fullscreen mode Exit fullscreen mode

The annotationId is a unique identifier for the annotation you want to remove. You can retrieve this ID from the annotationCollection array, making it simple to manage annotations dynamically.

Note: For advanced options and detailed examples, refer to the official documentation.

Managing PDF annotations

In addition to deleting, Syncfusion’s React PDF Viewer allows users to edit, customize, comment, export, and import annotations, ensuring a smooth and collaborative review process.

1. Add comments

To add comments, double-click an annotation or use the toolbar to open the Comment Panel. From there, you can add notes, reply to existing comments, and set statuses like “Accepted” or “Rejected” for collaborative reviews.

Add comments to PDF annotations using React PDF Viewer


Add comments to PDF annotations using React PDF Viewer

2. Customize annotations

Make annotations stand out by adjusting properties such as stroke or fill color, opacity, thickness, or font styles for free text annotations. These changes can be applied through the Properties Panel or programmatically via the API.

Customize PDF annotations using React PDF Viewer


Customize PDF annotations using React PDF Viewer

3. Export and import React PDF annotations

Syncfusion’s React PDF Viewer provides built-in support for saving annotations in XFDF or JSON formats, making it easy to persist, share, and reload annotations across sessions or applications.

Exporting annotations (XFDF Format)

To export annotations for storage or server-side processing, use the exportAnnotations method:

var xfdfData = pdfviewer.exportAnnotations();
console.log(xfdfData); // XFDF string
Enter fullscreen mode Exit fullscreen mode

This returns all annotations in XFDF format, which can be saved locally or sent to a backend for further handling.

Export and import PDF annotations


Export and import PDF annotations

Importing annotations

To restore previously saved annotations, use the importAnnotations method:

var savedData = localStorage.getItem('pdfAnnotations');
if (savedData) {
    pdfviewer.importAnnotations(savedData);
}

This allows you to reload annotations seamlessly, ensuring a consistent review experience.

4. Editing PDF annotations in the browser

Managing annotations is efficient and straightforward. Users can right-click any annotation to access quick actions such as cut, copy, paste, delete, or add comments. This streamlined approach eliminates the need for additional UI components, ensuring a faster and more intuitive review process.

Edit annotations without extra UI


Edit annotations without extra UI

Note: For a detailed exploration of all annotation management features, refer to the official documentation.

Conclusion

Thank you for reading! Implementing React PDF annotation with Syncfusion React PDF Viewer enhances your web application by enabling users to add highlights, sticky notes, shapes, stamps, ink, and free text directly within PDFs.

Developers can customize styles, manage annotations efficiently, and ensure persistence by saving to PDF or exporting/importing as JSON or XFDF, delivering a smooth, interactive document experience. Here’s what developers are saying about Syncfusion:

The PDF Viewer component offers all the functionality I could ask for and is fully customizable, G2 Reviewer.

Explore the live demo and check the implementation guide to learn how to add React PDF annotations.

If you’re a Syncfusion user, you can download the setup from the license and downloads page. Otherwise, you can download a free 30-day trial.

You can also contact us through our support forum, support portal, or feedback portal for queries. We are always happy to assist you!

Related Blogs

This article was originally published at Syncfusion.com.

Top comments (0)