Skip to content

Commit

Permalink
Add Name property for set custom icon for note() #1319
Browse files Browse the repository at this point in the history
  • Loading branch information
liborm85 committed Dec 28, 2024
1 parent cf5a774 commit bbe4ab9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Add support for spot colors
- Add support to scale text horizontally
- Add an option to keep the indentation after a new line starts and allow to indent a whole paragraph/text element
- Add `Name` property for set custom icon for `note()`
- Fix sets tab order to "Structure" when a document is tagged
- Fix font cache collision for fonts with missing postscript name or bad TTF metadata or identical metadata for different fonts
- Fix for embedding fonts into PDF (font name must not contain spaces)
Expand Down
10 changes: 10 additions & 0 deletions docs/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Many of the annotations have a `color` option that you can specify. You can
use an array of RGB values, a hex color, a named CSS color value, or a named
spot color value for that option.

A custom icon can be set using option `Name` property. Possible values are:
`'Comment'`, `'Key'`, `'Note'`, `'Help'`, `'NewParagraph'`, `'Paragraph'`
and `'Insert'`.

If you are adding an annotation to a piece of text, such as a link or
underline, you will need to know the width and height of the text in order to
create the required rectangle for the annotation. There are two methods that
Expand Down Expand Up @@ -69,6 +73,12 @@ Here is an example that uses a few of the annotation types.
.strike(20, doc.y, doc.widthOfString('STRIKE!'), height)
.text('STRIKE!');

// Create note
doc.note(10, 30, 30, 30, "Text of note");

// Create note with custom options
doc.note(10, 80, 30, 30, "Text of custom note", {Name: 'Key', color: 'red'});

// Adding go to as annotation
doc.goTo(20, doc.y, 10, 20, 'LINK', {});

Expand Down
4 changes: 3 additions & 1 deletion lib/mixins/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export default {
note(x, y, w, h, contents, options = {}) {
options.Subtype = 'Text';
options.Contents = new String(contents);
options.Name = 'Comment';
if (options.Name == null) {
options.Name = 'Comment';
}
if (options.color == null) {
options.color = [243, 223, 92];
}
Expand Down

0 comments on commit bbe4ab9

Please sign in to comment.