Adding free-text annotations to PDFs with the GemBox.PdfViewer JavaScript library

GemBox.PdfViewer allows you to add free text annotations to PDF documents opened in your browser - Chrome, Edge, Firefox, or any other major one. Custom text can be inserted directly onto any page. This feature is particularly useful for document review workflows and adding contextual information to existing PDFs.

Demonstration of adding free text annotations to a PDF document opened in a browser
Demonstration of adding free text annotations to a PDF document

Basic Usage

To enable the free text annotation functionality, configure the toolbar options when creating the viewer:

GemBoxPdfViewer.create({
    container: "#viewer",
    initialDocument: "/document.pdf",
    ui: {
        toolbar: {
            freeText: {
                isVisible: true // default
            }
        }
    }
});

With this configuration, users can click the free text button in the toolbar and add free text annotations to any page of a PDF document.

Programmatic Control

You can control the visibility of free text annotation controls programmatically after the viewer has been created:

const viewer = await GemBoxPdfViewer.create({
    container: "#viewer",
    initialDocument: "/document.pdf"
});

// Show free text controls
viewer.ui.toolbar.freeText.isVisible = true;

// Hide free text controls
viewer.ui.toolbar.freeText.isVisible = false;

// Check current visibility state
const isFreeTextVisible = viewer.ui.toolbar.freeText.isVisible;

viewer.features.annotations.addEventListener("annotationCreated", function (event) {
    // Whether the created annotation is free text.
    const isFreeText = event.annotation.type == AnnotationType.FREETEXT;
    if (isFreeText) {
        console.log("Free text annotation has been added.");
    }
});

See also


Next steps

GemBox.PdfViewer is a JavaScript library that enables you to show PDF files seamlessly in your web applications.

Download Buy