From bbe4ab9305b366dcda0295cd8ce084fea8a53ce2 Mon Sep 17 00:00:00 2001 From: "Libor M." Date: Sat, 28 Dec 2024 16:00:38 +0100 Subject: [PATCH] Add `Name` property for set custom icon for `note()` #1319 --- CHANGELOG.md | 1 + docs/annotations.md | 10 ++++++++++ lib/mixins/annotations.js | 4 +++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5fc436..ddb880a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/docs/annotations.md b/docs/annotations.md index 1627c53..2bc43c0 100644 --- a/docs/annotations.md +++ b/docs/annotations.md @@ -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 @@ -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', {}); diff --git a/lib/mixins/annotations.js b/lib/mixins/annotations.js index 4b3d9eb..1432aed 100644 --- a/lib/mixins/annotations.js +++ b/lib/mixins/annotations.js @@ -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]; }