Annotation example for PDF.js

HTML

<input type=file>

JavaScript

PDFJS.workerSrc = 'https://raw.githubusercontent.com/frontenddeveloping/pdfjs-dist/master/build/pdf.worker.js';

$(function () {
    var pdfData = loadPDFData();

    PDFJS.getDocument(pdfData).then(function (pdf) {
        return pdf.getPage(1);
    });

    function setupAnnotations(page, viewport, canvas, $annotationLayerDiv) {
        var promise = page.getAnnotations().then(function (annotationsData) {
            for (var i = 0; i < annotationsData.length; i++) {
                var data = annotationsData[i];
                var annotation = PDFJS.Annotation.fromData(data);
                if (!annotation || !annotation.hasHtml()) {
                    continue;
                }
                data = annotation.getData();
                if (data.subtype === 'Link' && !data.url) {
                    // In this example,  I do not handle the `Link` annotations without url.
                    // If you want to handle those links, see `web/page_view.js`.
                    continue;
                }
            }
        });
        return promise;
    }
});