- Notifications
You must be signed in to change notification settings - Fork79
An annotation extension based on the PDF.js viewer. Supporting the editing of existing PDF file annotations, posting comments, replying, submitting annotation data, and loading for further editing. 一个基于 PDF.js 阅读器的批注扩展,支持对现有 PDF 文件批注的编辑、发布评论、回复、提交批注数据以及加载后续编辑功能。
License
Laomai-codefee/pdfjs-annotation-extension
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
An annotation extension based on the PDF.js viewer
Supporting the editing of existing PDF file annotations, posting comments, replying, submitting annotation data, and loading for further editing.
🚀 Now supports exporting annotations to PDF files.
English |简体中文
Site:https://laomai-codefee.github.io/pdfjs-annotation-extension/
🔥🔥2025.6.27 v2.2.0 Version, main updates include:
- New Annotation Types – Added arrow and cloud line annotations
- Signature – Added support for creating signatures via text input or image upload; text input supports font selection
- Stamping – Added default stamps, custom stamp creation, and image-based stamp uploads; custom stamps support settings for text color, style, font, background, and border; timestamp supports username, date, and custom text
- Annotation Status – Added annotation status options: Accepted, Rejected, Canceled, Completed, Closed, and None
- Annotation Export – Added Excel export functionality for annotations
- Connecting Lines – Added connectors between annotations and shapes
- Annotation Styles – Added style settings for each annotation type, supporting color, stroke width, and opacity adjustments
- Bug Fixes and Interaction Improvements – Various bug fixes and optimizations to enhance user experience
2025.5.19 Version 2.1.1 – Key features include:
- Sidebar Collapse Support – Added
DEFAULT_SIDE_BAR_OPENto control whether the sidebar is shown. It is visible by default. - Annotation Filtering Support – Added annotation filtering functionality, allowing filters by author and annotation type.
- Improved Annotation Highlighting Logic – Annotations are now highlighted even when not selected, improving the overall user experience.
- Sidebar Collapse Support – Added
2025.5.16 Version 2.1.0 – Key features include:
- Added PDF export functionality: Export drawn annotations to a new PDF file. Supported annotation types: TEXT, HIGHLIGHT, UNDERLINE, STRIKEOUT, SQUARE, CIRCLE, INK, POLYLINE, FREETEXT, STAMP.
- Signatures and stamps: Introduced the
ALLOW_REPLY_ON_STAMPparameter to control whether comments/replies are allowed on stamps (disabled by default). - New Note annotation tool: Corresponds to the PDF Text annotation type.
PDF.js provides aViewer for online PDF preview and includes some basic annotation functionalities (FREETEXT, HIGHLIGHT, STAMP, INK).
In actual use cases, there is often a need for various annotation tools, leading to the idea of extending the viewer to add more annotation capabilities.
This project is based onkonva,react,antd, andweb-highlighter. It introduces additional annotation types by extending the existingpdf.js viewer without modifying its original code. Supports editing existing annotations, submitting annotation data, and loading for further editing, as shown below:
For PDF Viewer users, this is a highly useful feature. If your requirement is simple annotation, the current features in the project should suffice. For more specific needs or requirements, you can further develop based on this extension.
- Rectangle
- Circle
- Free Hand (grouped if drawn within a short time)
- Free Highlight (with auto-correction)
- Arrow
- Cloud
- FreeText
- Signature
- Stamp (upload custom images)
- Text Highlight
- Text Strikeout
- Text Underline
- Text
- Annotation Selection (use double-click to delete the selected object)
🚀 Now supports exporting annotations to PDF files.
- Square
- Circle
- Ink
- FreeText
- Line
- Polygon
- PolyLine
- Text
- Highlight
- Underline
- StrikeOut
$ npm install or yarn
$ npm run dev or yarn dev
A DEMO example is provided in the repository (located in the examples folder). Navigate to ./examples/pdfjs-4.3.136-dist:
$ miniserve or use another static server
Open the URL:http://localhost:8080/web/viewer.html to see the result.
ae_username= Name of the annotator, displayed as the annotator's name when adding annotations ae_get_url= URLfor annotation data, used to load previously saved annotation data. Example: ./examples/pdfjs-4.3.136-dist/pdfjs-annotation-extension-testdata.json ae_post_url= URLfor submitting annotation dataae_default_editor_active =true|false# Whether to activate the editor by default
ae_default_sidebar_open =true|false# Whether to open the sidebar by default
src/const/default_options.tsTo load PDF file annotations, modify:
LOAD_PDF_ANNOTATION: true, // Whether to load existing PDF annotationsNote:If you need to edit existing PDF annotations, you must set annotationMode in PDF.js to 0, so that PDF.js will not render the annotations
pdfjs-dist/web/viewer.mjs annotationMode: { value: 0, // Change to 0 kind: OptionKind.VIEWER + OptionKind.PREFERENCE }The configuration can be found in the /configuration/environment.js file. By default, it points to examples/pdfjs-4.3.136-dist/web/pdfjs-annotation-extension. You can modify it to match your local pdfjs-dist directory to facilitate development:
output: path.resolve(__dirname,'../examples/pdfjs-4.3.136-dist/web/pdfjs-annotation-extension'),$ npm run build or yarn build
Alternatively, you can directly download the release version.
Modify the pdfjs-dist/web/viewer.html file by adding a single line to include the generated extension file:
<scriptsrc="../build/pdf.mjs"type="module"></script><linkrel="stylesheet"href="viewer.css"><scriptsrc="viewer.mjs"type="module"></script><!-- Insert the generated annotation extension file --><scriptsrc="./pdfjs-annotation-extension/pdfjs-annotation-extension.js"type="module"></script><!-- End --></head>
By leveraging the pdfjs EventBus, we capture page events and dynamically insert a Konva drawing layer. Shapes are drawn on the Konva layer.Although there are more annotation types, they are essentially mapped to the ones supported by pdfjs with some additional custom transformations.
For details about pdfjs annotation types, please refer to the documentation here 👇https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-annotations
Currently, this extension has been tested only with pdfjs-4.3.136-dist.Note that it does not support drawing on rotated pages.
About
An annotation extension based on the PDF.js viewer. Supporting the editing of existing PDF file annotations, posting comments, replying, submitting annotation data, and loading for further editing. 一个基于 PDF.js 阅读器的批注扩展,支持对现有 PDF 文件批注的编辑、发布评论、回复、提交批注数据以及加载后续编辑功能。
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.

