Annotation layer for PDF.js.
Combined fork of archived instructure/pdf-annotate.js and deleted DynamicEnvironmentSystems/pdf-annotate.js. And forked from Submitty's development branch.
This modified pdf-annotate.js fixes a lot of bugs in Submitty's branch, and adds some features (such as undo/redo) that we need in Papera -- a software-enginnering class project.
I cannot promise to continue maintaining this after class ends, but it's welcome to create issue/pr if you find something wrong. pdf-annotate.js is buggy and broken compared with commerical and expensive PDF javascript libraries, but it is the best open-source PDF annotation javascript library working with PDF.js you can find on the web (especially the version maintained here, at least in 2020 it is).
- Provide a low level annotation layer for PDF.js.
- Optional high level UI for managing annotations.
- Agnostic of backend, just supply your own
StoreAdapter
to fetch/store data. - Prescribe annotation format.
import pdfjsLib from 'pdfjs-dist/build/pdf';
import PDFJSAnnotate from 'pdfjs-annotate';
const { UI } = PDFJSAnnotate;
const VIEWER = document.getElementById('viewer');
const RENDER_OPTIONS = {
documentId: 'MyPDF.pdf',
pdfDocument: null,
scale: 1,
rotate: 0
};
pdfjsLib.workerSrc = 'pdf.worker.js';
PDFJSAnnotate.setStoreAdapter(PDFJSAnnotate.LocalStoreAdapter);
pdfjsLib.getDocument(RENDER_OPTIONS.documentId).promise.then((pdf) => {
RENDER_OPTIONS.pdfDocument = pdf;
VIEWER.appendChild(UI.createPage(1));
UI.renderPage(1, RENDER_OPTIONS);
});
See /web for an example web client for annotating PDFs.
Although pdf-annotate.js
has no features relying on specific operating system, it can only be built in Unix-like systems now.
# clone the repo
$ git clone https://github.com/taoky/pdf-annotate.js.git
$ cd pdf-annotate.js
# intall dependencies
$ npm install
# start example server
$ npm start
$ open http://127.0.0.1:8080
# run tests
$ npm test
# lint the code
$ npm run lint