A JavaScript library for PDF annotation, using PDF.js and the Recogito Text Annotator.
npm install @recogito/pdf-annotatorimport { createPDFAnnotator } from '@recogito/pdf-annotator';
var anno = await createPDFAnnotator(
document.getElementById('container');,
'compressed.tracemonkey-pldi-09.pdf'
);
// Load annotations from a file
anno.loadAnnotations('annotations.json');
// Listen to user events
anno.on('createAnnotation', annotation => {
console.log('new annotation', annotation);
}); const anno = createPDFAnnotator(element, url, options);| Option | Type | Default | Description |
|---|---|---|---|
annotatingEnabled |
boolean |
true |
Enable or disable interactive creation of new annotations. |
dismissOnNotAnnotatable |
'NEVER' | 'ALWAYS' | function |
'NEVER' |
Controls whether the current selection is dismissed when clicking outside of annotatable content. |
mergeHighlights |
object |
undefined |
Merge adjacent highlights. Options: horizontalTolerance and verticalTolerance (in pixels) |
selectionMode |
'shortest' | 'all' |
'shortest' |
When the user selects overlapping annotations: select all or only the shortest. |
style |
HighlightStyleExpression |
undefined |
Custom styling function for highlights. |
user |
User |
anonymous guest | Current user information, automatically added to created or updated annotations. |
The current numeric scale value of the PDF viewer.
console.log(anno.currentScale);The current scale setting value of the PDF viewer.
console.log(anno.currentScaleValue); // e.g. 'page-fit'The PDF annotator supports all the API methods of the underlying text annotator instance. The following additional methods are available:
Sets the PDF viewer scale.
anno.setScale(2);
anno.setScale('page-fit');Zoom the PDF viewer by a given percentage (default: 10).
anno.zoomIn();Zoom the PDF viewer out by a given percentage (default: 10).
anno.zoomOut();The PDF annotator supports all the events of the underlying text annotator instance.
