@lexmata/micropdf 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +985 -0
- package/binding.gyp +73 -0
- package/dist/annot.d.ts +458 -0
- package/dist/annot.d.ts.map +1 -0
- package/dist/annot.js +697 -0
- package/dist/annot.js.map +1 -0
- package/dist/archive.d.ts +128 -0
- package/dist/archive.d.ts.map +1 -0
- package/dist/archive.js +268 -0
- package/dist/archive.js.map +1 -0
- package/dist/buffer.d.ts +572 -0
- package/dist/buffer.d.ts.map +1 -0
- package/dist/buffer.js +971 -0
- package/dist/buffer.js.map +1 -0
- package/dist/colorspace.d.ts +287 -0
- package/dist/colorspace.d.ts.map +1 -0
- package/dist/colorspace.js +542 -0
- package/dist/colorspace.js.map +1 -0
- package/dist/context.d.ts +184 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +320 -0
- package/dist/context.js.map +1 -0
- package/dist/cookie.d.ts +164 -0
- package/dist/cookie.d.ts.map +1 -0
- package/dist/cookie.js +306 -0
- package/dist/cookie.js.map +1 -0
- package/dist/device.d.ts +169 -0
- package/dist/device.d.ts.map +1 -0
- package/dist/device.js +350 -0
- package/dist/device.js.map +1 -0
- package/dist/display-list.d.ts +202 -0
- package/dist/display-list.d.ts.map +1 -0
- package/dist/display-list.js +410 -0
- package/dist/display-list.js.map +1 -0
- package/dist/document.d.ts +637 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +902 -0
- package/dist/document.js.map +1 -0
- package/dist/easy.d.ts +423 -0
- package/dist/easy.d.ts.map +1 -0
- package/dist/easy.js +644 -0
- package/dist/easy.js.map +1 -0
- package/dist/enhanced.d.ts +226 -0
- package/dist/enhanced.d.ts.map +1 -0
- package/dist/enhanced.js +368 -0
- package/dist/enhanced.js.map +1 -0
- package/dist/filter.d.ts +51 -0
- package/dist/filter.d.ts.map +1 -0
- package/dist/filter.js +381 -0
- package/dist/filter.js.map +1 -0
- package/dist/font.d.ts +222 -0
- package/dist/font.d.ts.map +1 -0
- package/dist/font.js +381 -0
- package/dist/font.js.map +1 -0
- package/dist/form.d.ts +214 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +497 -0
- package/dist/form.js.map +1 -0
- package/dist/geometry.d.ts +469 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +780 -0
- package/dist/geometry.js.map +1 -0
- package/dist/image.d.ts +172 -0
- package/dist/image.d.ts.map +1 -0
- package/dist/image.js +348 -0
- package/dist/image.js.map +1 -0
- package/dist/index.d.ts +171 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +339 -0
- package/dist/index.js.map +1 -0
- package/dist/link.d.ts +168 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +343 -0
- package/dist/link.js.map +1 -0
- package/dist/micropdf.d.ts +40 -0
- package/dist/micropdf.d.ts.map +1 -0
- package/dist/micropdf.js +45 -0
- package/dist/micropdf.js.map +1 -0
- package/dist/nanopdf.d.ts +40 -0
- package/dist/nanopdf.d.ts.map +1 -0
- package/dist/nanopdf.js +45 -0
- package/dist/nanopdf.js.map +1 -0
- package/dist/native.d.ts +242 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +509 -0
- package/dist/native.js.map +1 -0
- package/dist/output.d.ts +166 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +365 -0
- package/dist/output.js.map +1 -0
- package/dist/path.d.ts +420 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +687 -0
- package/dist/path.js.map +1 -0
- package/dist/pdf/object.d.ts +489 -0
- package/dist/pdf/object.d.ts.map +1 -0
- package/dist/pdf/object.js +1045 -0
- package/dist/pdf/object.js.map +1 -0
- package/dist/pixmap.d.ts +315 -0
- package/dist/pixmap.d.ts.map +1 -0
- package/dist/pixmap.js +590 -0
- package/dist/pixmap.js.map +1 -0
- package/dist/profiler.d.ts +159 -0
- package/dist/profiler.d.ts.map +1 -0
- package/dist/profiler.js +380 -0
- package/dist/profiler.js.map +1 -0
- package/dist/render-options.d.ts +227 -0
- package/dist/render-options.d.ts.map +1 -0
- package/dist/render-options.js +130 -0
- package/dist/render-options.js.map +1 -0
- package/dist/resource-tracking.d.ts +332 -0
- package/dist/resource-tracking.d.ts.map +1 -0
- package/dist/resource-tracking.js +653 -0
- package/dist/resource-tracking.js.map +1 -0
- package/dist/simple.d.ts +276 -0
- package/dist/simple.d.ts.map +1 -0
- package/dist/simple.js +343 -0
- package/dist/simple.js.map +1 -0
- package/dist/stext.d.ts +290 -0
- package/dist/stext.d.ts.map +1 -0
- package/dist/stext.js +312 -0
- package/dist/stext.js.map +1 -0
- package/dist/stream.d.ts +174 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +476 -0
- package/dist/stream.js.map +1 -0
- package/dist/text.d.ts +337 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +454 -0
- package/dist/text.js.map +1 -0
- package/dist/typed-arrays.d.ts +127 -0
- package/dist/typed-arrays.d.ts.map +1 -0
- package/dist/typed-arrays.js +410 -0
- package/dist/typed-arrays.js.map +1 -0
- package/dist/types.d.ts +358 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +216 -0
- package/dist/types.js.map +1 -0
- package/native/annot.cc +557 -0
- package/native/buffer.cc +204 -0
- package/native/colorspace.cc +166 -0
- package/native/context.cc +84 -0
- package/native/cookie.cc +179 -0
- package/native/device.cc +179 -0
- package/native/display_list.cc +179 -0
- package/native/document.cc +268 -0
- package/native/enhanced.cc +70 -0
- package/native/font.cc +282 -0
- package/native/form.cc +523 -0
- package/native/geometry.cc +255 -0
- package/native/image.cc +216 -0
- package/native/include/micropdf/enhanced.h +38 -0
- package/native/include/micropdf/types.h +36 -0
- package/native/include/micropdf.h +106 -0
- package/native/include/mupdf-ffi.h +39 -0
- package/native/include/mupdf.h +11 -0
- package/native/include/mupdf_minimal.h +381 -0
- package/native/lib/linux-x64/libmicropdf.a +0 -0
- package/native/link.cc +234 -0
- package/native/micropdf.cc +71 -0
- package/native/output.cc +229 -0
- package/native/page.cc +572 -0
- package/native/path.cc +259 -0
- package/native/pixmap.cc +240 -0
- package/native/stext.cc +610 -0
- package/native/stream.cc +239 -0
- package/package.json +120 -0
- package/scripts/build-from-rust.js +97 -0
- package/scripts/install.js +184 -0
package/binding.gyp
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"target_name": "micropdf",
|
|
5
|
+
"cflags!": ["-fno-exceptions"],
|
|
6
|
+
"cflags_cc!": ["-fno-exceptions"],
|
|
7
|
+
"sources": [
|
|
8
|
+
"native/micropdf.cc",
|
|
9
|
+
"native/context.cc",
|
|
10
|
+
"native/document.cc",
|
|
11
|
+
"native/page.cc",
|
|
12
|
+
"native/stext.cc",
|
|
13
|
+
"native/annot.cc",
|
|
14
|
+
"native/form.cc",
|
|
15
|
+
"native/display_list.cc",
|
|
16
|
+
"native/link.cc",
|
|
17
|
+
"native/cookie.cc",
|
|
18
|
+
"native/device.cc",
|
|
19
|
+
"native/path.cc",
|
|
20
|
+
"native/pixmap.cc",
|
|
21
|
+
"native/image.cc",
|
|
22
|
+
"native/colorspace.cc",
|
|
23
|
+
"native/font.cc",
|
|
24
|
+
"native/stream.cc",
|
|
25
|
+
"native/output.cc",
|
|
26
|
+
"native/enhanced.cc"
|
|
27
|
+
],
|
|
28
|
+
"include_dirs": [
|
|
29
|
+
"<!@(node -p \"require('node-addon-api').include\")",
|
|
30
|
+
"native/include"
|
|
31
|
+
],
|
|
32
|
+
"defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"],
|
|
33
|
+
"conditions": [
|
|
34
|
+
["OS=='linux'", {
|
|
35
|
+
"libraries": [
|
|
36
|
+
"<(module_root_dir)/native/lib/linux-<(target_arch)/libmicropdf.a",
|
|
37
|
+
"-lpthread",
|
|
38
|
+
"-ldl",
|
|
39
|
+
"-lm"
|
|
40
|
+
],
|
|
41
|
+
"cflags": ["-fPIC"]
|
|
42
|
+
}],
|
|
43
|
+
["OS=='mac'", {
|
|
44
|
+
"libraries": [
|
|
45
|
+
"<(module_root_dir)/native/lib/darwin-<(target_arch)/libmicropdf.a",
|
|
46
|
+
"-framework CoreFoundation",
|
|
47
|
+
"-framework Security"
|
|
48
|
+
],
|
|
49
|
+
"xcode_settings": {
|
|
50
|
+
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
|
51
|
+
"CLANG_CXX_LIBRARY": "libc++",
|
|
52
|
+
"MACOSX_DEPLOYMENT_TARGET": "10.15"
|
|
53
|
+
}
|
|
54
|
+
}],
|
|
55
|
+
["OS=='win'", {
|
|
56
|
+
"libraries": [
|
|
57
|
+
"<(module_root_dir)/native/lib/win32-<(target_arch)/micropdf.lib",
|
|
58
|
+
"ws2_32.lib",
|
|
59
|
+
"userenv.lib",
|
|
60
|
+
"bcrypt.lib",
|
|
61
|
+
"ntdll.lib"
|
|
62
|
+
],
|
|
63
|
+
"msvs_settings": {
|
|
64
|
+
"VCCLCompilerTool": {
|
|
65
|
+
"ExceptionHandling": 1
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}]
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
|
package/dist/annot.d.ts
ADDED
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Annot - PDF annotation handling
|
|
3
|
+
*
|
|
4
|
+
* This module provides comprehensive PDF annotation support with 100% API compatibility
|
|
5
|
+
* with MuPDF's annotation operations. It supports creating, modifying, and managing
|
|
6
|
+
* various types of PDF annotations including text notes, highlights, stamps, shapes,
|
|
7
|
+
* ink annotations, and more.
|
|
8
|
+
*
|
|
9
|
+
* **Key Features:**
|
|
10
|
+
* - 28 annotation types (text, highlight, stamp, ink, shapes, etc.)
|
|
11
|
+
* - Complete annotation properties (color, opacity, borders, etc.)
|
|
12
|
+
* - Annotation lifecycle management (creation, modification, deletion)
|
|
13
|
+
* - Dirty tracking for efficient updates
|
|
14
|
+
* - Reference counting for memory management
|
|
15
|
+
*
|
|
16
|
+
* **Supported Annotation Types:**
|
|
17
|
+
* - **Text Markup**: Highlight, Underline, Squiggly, StrikeOut
|
|
18
|
+
* - **Note Annotations**: Text, FreeText
|
|
19
|
+
* - **Shape Annotations**: Square, Circle, Line, Polygon, PolyLine
|
|
20
|
+
* - **Stamp Annotations**: Stamp (Approved, Draft, etc.)
|
|
21
|
+
* - **Drawing Annotations**: Ink (freehand drawing)
|
|
22
|
+
* - **Special Types**: Link, FileAttachment, Sound, Movie, Widget, etc.
|
|
23
|
+
*
|
|
24
|
+
* @example Basic usage:
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { Annotation, AnnotationType, AnnotationFlags } from 'micropdf';
|
|
27
|
+
*
|
|
28
|
+
* // Create a text annotation
|
|
29
|
+
* const textAnnot = Annotation.createText(
|
|
30
|
+
* { x0: 100, y0: 100, x1: 150, y1: 120 },
|
|
31
|
+
* 'This is a note'
|
|
32
|
+
* );
|
|
33
|
+
*
|
|
34
|
+
* // Create a highlight annotation
|
|
35
|
+
* const highlightAnnot = Annotation.createHighlight(
|
|
36
|
+
* { x0: 50, y0: 200, x1: 300, y1: 220 },
|
|
37
|
+
* [1, 1, 0] // Yellow
|
|
38
|
+
* );
|
|
39
|
+
*
|
|
40
|
+
* // Modify annotation properties
|
|
41
|
+
* highlightAnnot.opacity = 0.5;
|
|
42
|
+
* highlightAnnot.author = 'John Doe';
|
|
43
|
+
* highlightAnnot.setFlag(AnnotationFlags.Print, true);
|
|
44
|
+
*
|
|
45
|
+
* // Check if annotation was modified
|
|
46
|
+
* if (highlightAnnot.isDirty) {
|
|
47
|
+
* // Update appearance
|
|
48
|
+
* highlightAnnot.update();
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @module annot
|
|
53
|
+
*/
|
|
54
|
+
import { Rect, Point, type RectLike, type PointLike } from './geometry.js';
|
|
55
|
+
/**
|
|
56
|
+
* PDF annotation types.
|
|
57
|
+
*
|
|
58
|
+
* These correspond to the standard PDF annotation types as defined in the PDF specification.
|
|
59
|
+
* Each type has specific rendering behavior and properties.
|
|
60
|
+
*
|
|
61
|
+
* @enum {number}
|
|
62
|
+
*/
|
|
63
|
+
export declare enum AnnotationType {
|
|
64
|
+
/** Text note annotation - sticky note icon */
|
|
65
|
+
Text = 0,
|
|
66
|
+
/** Link annotation - hyperlink to URL or document location */
|
|
67
|
+
Link = 1,
|
|
68
|
+
/** Free text annotation - text directly on page */
|
|
69
|
+
FreeText = 2,
|
|
70
|
+
/** Line annotation - straight line with optional endpoints */
|
|
71
|
+
Line = 3,
|
|
72
|
+
/** Square annotation - rectangle shape */
|
|
73
|
+
Square = 4,
|
|
74
|
+
/** Circle annotation - circle/ellipse shape */
|
|
75
|
+
Circle = 5,
|
|
76
|
+
/** Polygon annotation - closed polygon shape */
|
|
77
|
+
Polygon = 6,
|
|
78
|
+
/** PolyLine annotation - open polyline shape */
|
|
79
|
+
PolyLine = 7,
|
|
80
|
+
/** Highlight annotation - text markup highlighting */
|
|
81
|
+
Highlight = 8,
|
|
82
|
+
/** Underline annotation - text markup underlining */
|
|
83
|
+
Underline = 9,
|
|
84
|
+
/** Squiggly annotation - text markup squiggly underline */
|
|
85
|
+
Squiggly = 10,
|
|
86
|
+
/** StrikeOut annotation - text markup strikethrough */
|
|
87
|
+
StrikeOut = 11,
|
|
88
|
+
/** Stamp annotation - rubber stamp (Approved, Draft, etc.) */
|
|
89
|
+
Stamp = 12,
|
|
90
|
+
/** Caret annotation - text insertion point */
|
|
91
|
+
Caret = 13,
|
|
92
|
+
/** Ink annotation - freehand drawing paths */
|
|
93
|
+
Ink = 14,
|
|
94
|
+
/** Popup annotation - popup window for another annotation */
|
|
95
|
+
Popup = 15,
|
|
96
|
+
/** File attachment annotation - embedded file */
|
|
97
|
+
FileAttachment = 16,
|
|
98
|
+
/** Sound annotation - embedded sound */
|
|
99
|
+
Sound = 17,
|
|
100
|
+
/** Movie annotation - embedded video */
|
|
101
|
+
Movie = 18,
|
|
102
|
+
/** Widget annotation - interactive form field */
|
|
103
|
+
Widget = 19,
|
|
104
|
+
/** Screen annotation - multimedia screen */
|
|
105
|
+
Screen = 20,
|
|
106
|
+
/** Printer mark annotation - printing marks */
|
|
107
|
+
PrinterMark = 21,
|
|
108
|
+
/** Trap net annotation - color separation trapping */
|
|
109
|
+
TrapNet = 22,
|
|
110
|
+
/** Watermark annotation - page watermark */
|
|
111
|
+
Watermark = 23,
|
|
112
|
+
/** 3D annotation - 3D artwork */
|
|
113
|
+
ThreeD = 24,
|
|
114
|
+
/** Redact annotation - content to be redacted */
|
|
115
|
+
Redact = 25
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Annotation flags (bit flags).
|
|
119
|
+
*
|
|
120
|
+
* These flags control the visibility, behavior, and interaction of annotations.
|
|
121
|
+
* Multiple flags can be combined using bitwise OR operations.
|
|
122
|
+
*
|
|
123
|
+
* @example Using annotation flags:
|
|
124
|
+
* ```typescript
|
|
125
|
+
* import { Annotation, AnnotationFlags } from 'micropdf';
|
|
126
|
+
*
|
|
127
|
+
* const annot = Annotation.createText(rect, 'Note');
|
|
128
|
+
*
|
|
129
|
+
* // Set multiple flags
|
|
130
|
+
* annot.setFlags(AnnotationFlags.Print | AnnotationFlags.ReadOnly);
|
|
131
|
+
*
|
|
132
|
+
* // Check if a flag is set
|
|
133
|
+
* if (annot.hasFlag(AnnotationFlags.Print)) {
|
|
134
|
+
* console.log('Annotation will be printed');
|
|
135
|
+
* }
|
|
136
|
+
*
|
|
137
|
+
* // Toggle a flag
|
|
138
|
+
* annot.setFlag(AnnotationFlags.Hidden, true);
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @enum {number}
|
|
142
|
+
*/
|
|
143
|
+
export declare enum AnnotationFlags {
|
|
144
|
+
/** Annotation is invisible (not displayed or printed) */
|
|
145
|
+
Invisible = 1,
|
|
146
|
+
/** Annotation is hidden (not displayed, but may be printed) */
|
|
147
|
+
Hidden = 2,
|
|
148
|
+
/** Annotation should be printed */
|
|
149
|
+
Print = 4,
|
|
150
|
+
/** Annotation should not scale with zoom */
|
|
151
|
+
NoZoom = 8,
|
|
152
|
+
/** Annotation should not rotate with page */
|
|
153
|
+
NoRotate = 16,
|
|
154
|
+
/** Annotation should not be viewed (but may be printed) */
|
|
155
|
+
NoView = 32,
|
|
156
|
+
/** Annotation is read-only (cannot be modified or deleted) */
|
|
157
|
+
ReadOnly = 64,
|
|
158
|
+
/** Annotation is locked (cannot be moved or resized) */
|
|
159
|
+
Locked = 128,
|
|
160
|
+
/** Toggle NoView flag based on user actions */
|
|
161
|
+
ToggleNoView = 256,
|
|
162
|
+
/** Annotation contents are locked (cannot be edited) */
|
|
163
|
+
LockedContents = 512
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Line ending styles for line annotations.
|
|
167
|
+
*
|
|
168
|
+
* These styles define the appearance of line endings for Line, PolyLine,
|
|
169
|
+
* and Polygon annotations.
|
|
170
|
+
*
|
|
171
|
+
* @example Using line ending styles:
|
|
172
|
+
* ```typescript
|
|
173
|
+
* import { Annotation, LineEndingStyle } from 'micropdf';
|
|
174
|
+
*
|
|
175
|
+
* const lineAnnot = Annotation.createLine(rect, start, end);
|
|
176
|
+
* lineAnnot.lineStartStyle = LineEndingStyle.OpenArrow;
|
|
177
|
+
* lineAnnot.lineEndStyle = LineEndingStyle.ClosedArrow;
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* @enum {number}
|
|
181
|
+
*/
|
|
182
|
+
export declare enum LineEndingStyle {
|
|
183
|
+
/** No line ending */
|
|
184
|
+
None = 0,
|
|
185
|
+
/** Square line ending */
|
|
186
|
+
Square = 1,
|
|
187
|
+
/** Circle line ending */
|
|
188
|
+
Circle = 2,
|
|
189
|
+
/** Diamond line ending */
|
|
190
|
+
Diamond = 3,
|
|
191
|
+
/** Open arrow line ending */
|
|
192
|
+
OpenArrow = 4,
|
|
193
|
+
/** Closed arrow line ending (filled) */
|
|
194
|
+
ClosedArrow = 5,
|
|
195
|
+
/** Butt line ending (perpendicular cap) */
|
|
196
|
+
Butt = 6,
|
|
197
|
+
/** Reverse open arrow */
|
|
198
|
+
ROpenArrow = 7,
|
|
199
|
+
/** Reverse closed arrow (filled) */
|
|
200
|
+
RClosedArrow = 8,
|
|
201
|
+
/** Slash line ending (diagonal cap) */
|
|
202
|
+
Slash = 9
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* A PDF annotation.
|
|
206
|
+
*
|
|
207
|
+
* Represents a single PDF annotation with all its properties and methods.
|
|
208
|
+
* Annotations can be text notes, highlights, shapes, stamps, ink drawings, and more.
|
|
209
|
+
*
|
|
210
|
+
* **Lifecycle:**
|
|
211
|
+
* 1. Create annotation using static factory methods or constructor
|
|
212
|
+
* 2. Modify properties (color, opacity, contents, etc.)
|
|
213
|
+
* 3. Check `isDirty` to see if annotation needs updating
|
|
214
|
+
* 4. Call `update()` to update appearance
|
|
215
|
+
* 5. Increment/decrement reference count for memory management
|
|
216
|
+
* 6. Drop annotation when done (`drop()`)
|
|
217
|
+
*
|
|
218
|
+
* **Properties:**
|
|
219
|
+
* - Type, rectangle, flags
|
|
220
|
+
* - Contents, author, subject
|
|
221
|
+
* - Color, opacity, borders
|
|
222
|
+
* - Line endpoints and styles (for line annotations)
|
|
223
|
+
* - Modification date
|
|
224
|
+
* - Popup association
|
|
225
|
+
*
|
|
226
|
+
* **Methods:**
|
|
227
|
+
* - Getters/setters for all properties
|
|
228
|
+
* - Type checking (`isHighlight()`, `isStamp()`, etc.)
|
|
229
|
+
* - Dirty tracking (`isDirty`, `markDirty()`, `clearDirty()`)
|
|
230
|
+
* - Reference counting (`keep()`, `drop()`)
|
|
231
|
+
* - Appearance updates (`update()`)
|
|
232
|
+
* - Cloning (`clone()`)
|
|
233
|
+
*
|
|
234
|
+
* @example Creating and modifying annotations:
|
|
235
|
+
* ```typescript
|
|
236
|
+
* // Create a highlight annotation
|
|
237
|
+
* const highlight = Annotation.createHighlight(
|
|
238
|
+
* { x0: 100, y0: 200, x1: 400, y1: 220 },
|
|
239
|
+
* [1, 1, 0] // Yellow
|
|
240
|
+
* );
|
|
241
|
+
*
|
|
242
|
+
* // Modify properties
|
|
243
|
+
* highlight.opacity = 0.3;
|
|
244
|
+
* highlight.author = 'John Doe';
|
|
245
|
+
* highlight.contents = 'Important section';
|
|
246
|
+
*
|
|
247
|
+
* // Check if modified
|
|
248
|
+
* if (highlight.isDirty) {
|
|
249
|
+
* highlight.update(); // Update appearance
|
|
250
|
+
* }
|
|
251
|
+
*
|
|
252
|
+
* // Clone annotation
|
|
253
|
+
* const copy = highlight.clone();
|
|
254
|
+
*
|
|
255
|
+
* // Clean up
|
|
256
|
+
* highlight.drop();
|
|
257
|
+
* copy.drop();
|
|
258
|
+
* ```
|
|
259
|
+
*
|
|
260
|
+
* @example Working with different annotation types:
|
|
261
|
+
* ```typescript
|
|
262
|
+
* // Text note
|
|
263
|
+
* const note = Annotation.createText(rect, 'Important!');
|
|
264
|
+
* note.setFlag(AnnotationFlags.ReadOnly, true);
|
|
265
|
+
*
|
|
266
|
+
* // Stamp
|
|
267
|
+
* const stamp = Annotation.createStamp(rect, 'Approved');
|
|
268
|
+
* stamp.color = [0, 1, 0]; // Green
|
|
269
|
+
*
|
|
270
|
+
* // Line with arrows
|
|
271
|
+
* const line = Annotation.createLine(rect, start, end);
|
|
272
|
+
* line.lineStartStyle = LineEndingStyle.OpenArrow;
|
|
273
|
+
* line.lineEndStyle = LineEndingStyle.ClosedArrow;
|
|
274
|
+
*
|
|
275
|
+
* // Free text
|
|
276
|
+
* const freeText = Annotation.createFreeText(rect, 'This is text');
|
|
277
|
+
* freeText.borderWidth = 2;
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* @class
|
|
281
|
+
*/
|
|
282
|
+
export declare class Annotation {
|
|
283
|
+
private _type;
|
|
284
|
+
private _rect;
|
|
285
|
+
private _flags;
|
|
286
|
+
private _contents;
|
|
287
|
+
private _author;
|
|
288
|
+
private _color;
|
|
289
|
+
private _interiorColor;
|
|
290
|
+
private _borderWidth;
|
|
291
|
+
private _opacity;
|
|
292
|
+
private _lineStart;
|
|
293
|
+
private _lineEnd;
|
|
294
|
+
private _refCount;
|
|
295
|
+
private _dirty;
|
|
296
|
+
private _hasPopup;
|
|
297
|
+
/**
|
|
298
|
+
* Creates a new PDF annotation.
|
|
299
|
+
*
|
|
300
|
+
* **Note**: Prefer using static factory methods (e.g., `createHighlight()`, `createStamp()`)
|
|
301
|
+
* instead of the constructor for better type safety and convenience.
|
|
302
|
+
*
|
|
303
|
+
* @param type - The annotation type
|
|
304
|
+
* @param rect - The annotation rectangle on the page
|
|
305
|
+
*
|
|
306
|
+
* @example Using the constructor:
|
|
307
|
+
* ```typescript
|
|
308
|
+
* const annot = new Annotation(AnnotationType.Square, {
|
|
309
|
+
* x0: 100, y0: 100, x1: 200, y1: 200
|
|
310
|
+
* });
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
constructor(type: AnnotationType, rect: RectLike);
|
|
314
|
+
/**
|
|
315
|
+
* Create a new annotation (alias for constructor).
|
|
316
|
+
*
|
|
317
|
+
* @param type - The annotation type
|
|
318
|
+
* @param rect - The annotation rectangle
|
|
319
|
+
* @returns A new annotation instance
|
|
320
|
+
*
|
|
321
|
+
* @deprecated Use static factory methods instead (e.g., `createHighlight()`)
|
|
322
|
+
*/
|
|
323
|
+
static create(type: AnnotationType, rect: RectLike): Annotation;
|
|
324
|
+
keep(): this;
|
|
325
|
+
drop(): void;
|
|
326
|
+
/**
|
|
327
|
+
* Clone this annotation
|
|
328
|
+
*/
|
|
329
|
+
clone(): Annotation;
|
|
330
|
+
get type(): AnnotationType;
|
|
331
|
+
get rect(): Rect;
|
|
332
|
+
set rect(r: RectLike);
|
|
333
|
+
get flags(): number;
|
|
334
|
+
set flags(f: number);
|
|
335
|
+
hasFlag(flag: AnnotationFlags): boolean;
|
|
336
|
+
setFlag(flag: AnnotationFlags, value: boolean): void;
|
|
337
|
+
get isHidden(): boolean;
|
|
338
|
+
set isHidden(value: boolean);
|
|
339
|
+
get isPrintable(): boolean;
|
|
340
|
+
set isPrintable(value: boolean);
|
|
341
|
+
get isReadOnly(): boolean;
|
|
342
|
+
set isReadOnly(value: boolean);
|
|
343
|
+
get isLocked(): boolean;
|
|
344
|
+
set isLocked(value: boolean);
|
|
345
|
+
get contents(): string;
|
|
346
|
+
set contents(text: string);
|
|
347
|
+
get author(): string;
|
|
348
|
+
set author(name: string);
|
|
349
|
+
get color(): number[];
|
|
350
|
+
set color(rgb: number[]);
|
|
351
|
+
get interiorColor(): number[];
|
|
352
|
+
set interiorColor(rgb: number[]);
|
|
353
|
+
get borderWidth(): number;
|
|
354
|
+
set borderWidth(width: number);
|
|
355
|
+
get opacity(): number;
|
|
356
|
+
set opacity(alpha: number);
|
|
357
|
+
get lineStart(): Point;
|
|
358
|
+
get lineEnd(): Point;
|
|
359
|
+
setLine(start: PointLike, end: PointLike): void;
|
|
360
|
+
getLine(): [Point, Point];
|
|
361
|
+
get hasPopup(): boolean;
|
|
362
|
+
set hasPopup(value: boolean);
|
|
363
|
+
get isDirty(): boolean;
|
|
364
|
+
clearDirty(): void;
|
|
365
|
+
/**
|
|
366
|
+
* Update the annotation (mark for re-rendering)
|
|
367
|
+
*/
|
|
368
|
+
update(): void;
|
|
369
|
+
isValid(): boolean;
|
|
370
|
+
/**
|
|
371
|
+
* Create a text note annotation
|
|
372
|
+
*/
|
|
373
|
+
static createText(rect: RectLike, contents?: string, author?: string): Annotation;
|
|
374
|
+
/**
|
|
375
|
+
* Create a highlight annotation
|
|
376
|
+
*/
|
|
377
|
+
static createHighlight(rect: RectLike, color?: number[]): Annotation;
|
|
378
|
+
/**
|
|
379
|
+
* Create an underline annotation
|
|
380
|
+
*/
|
|
381
|
+
static createUnderline(rect: RectLike, color?: number[]): Annotation;
|
|
382
|
+
/**
|
|
383
|
+
* Create a strikeout annotation
|
|
384
|
+
*/
|
|
385
|
+
static createStrikeOut(rect: RectLike, color?: number[]): Annotation;
|
|
386
|
+
/**
|
|
387
|
+
* Create a squiggly underline annotation
|
|
388
|
+
*/
|
|
389
|
+
static createSquiggly(rect: RectLike, color?: number[]): Annotation;
|
|
390
|
+
/**
|
|
391
|
+
* Create a line annotation
|
|
392
|
+
*/
|
|
393
|
+
static createLine(rect: RectLike, start: PointLike, end: PointLike, color?: number[]): Annotation;
|
|
394
|
+
/**
|
|
395
|
+
* Create a square annotation
|
|
396
|
+
*/
|
|
397
|
+
static createSquare(rect: RectLike, color?: number[]): Annotation;
|
|
398
|
+
/**
|
|
399
|
+
* Create a circle annotation
|
|
400
|
+
*/
|
|
401
|
+
static createCircle(rect: RectLike, color?: number[]): Annotation;
|
|
402
|
+
/**
|
|
403
|
+
* Create an ink annotation (freehand drawing)
|
|
404
|
+
*/
|
|
405
|
+
static createInk(rect: RectLike, color?: number[]): Annotation;
|
|
406
|
+
/**
|
|
407
|
+
* Create a stamp annotation
|
|
408
|
+
*/
|
|
409
|
+
static createStamp(rect: RectLike, stampText?: string): Annotation;
|
|
410
|
+
/**
|
|
411
|
+
* Create a free text annotation
|
|
412
|
+
*/
|
|
413
|
+
static createFreeText(rect: RectLike, text?: string): Annotation;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Annotation list manager for a page
|
|
417
|
+
*/
|
|
418
|
+
export declare class AnnotationList {
|
|
419
|
+
private _annotations;
|
|
420
|
+
constructor();
|
|
421
|
+
/**
|
|
422
|
+
* Add an annotation
|
|
423
|
+
*/
|
|
424
|
+
add(annot: Annotation): void;
|
|
425
|
+
/**
|
|
426
|
+
* Delete an annotation
|
|
427
|
+
*/
|
|
428
|
+
delete(annot: Annotation): boolean;
|
|
429
|
+
/**
|
|
430
|
+
* Get annotation count
|
|
431
|
+
*/
|
|
432
|
+
get count(): number;
|
|
433
|
+
/**
|
|
434
|
+
* Get annotation by index
|
|
435
|
+
*/
|
|
436
|
+
get(index: number): Annotation | undefined;
|
|
437
|
+
/**
|
|
438
|
+
* Get first annotation
|
|
439
|
+
*/
|
|
440
|
+
first(): Annotation | undefined;
|
|
441
|
+
/**
|
|
442
|
+
* Get next annotation after the given one
|
|
443
|
+
*/
|
|
444
|
+
next(current: Annotation): Annotation | undefined;
|
|
445
|
+
/**
|
|
446
|
+
* Get all annotations
|
|
447
|
+
*/
|
|
448
|
+
getAll(): Annotation[];
|
|
449
|
+
/**
|
|
450
|
+
* Clear all annotations
|
|
451
|
+
*/
|
|
452
|
+
clear(): void;
|
|
453
|
+
/**
|
|
454
|
+
* Iterate over annotations
|
|
455
|
+
*/
|
|
456
|
+
[Symbol.iterator](): Generator<Annotation>;
|
|
457
|
+
}
|
|
458
|
+
//# sourceMappingURL=annot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annot.d.ts","sourceRoot":"","sources":["../src/annot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAEH,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAE3E;;;;;;;GAOG;AACH,oBAAY,cAAc;IACxB,8CAA8C;IAC9C,IAAI,IAAI;IACR,8DAA8D;IAC9D,IAAI,IAAI;IACR,mDAAmD;IACnD,QAAQ,IAAI;IACZ,8DAA8D;IAC9D,IAAI,IAAI;IACR,0CAA0C;IAC1C,MAAM,IAAI;IACV,+CAA+C;IAC/C,MAAM,IAAI;IACV,gDAAgD;IAChD,OAAO,IAAI;IACX,gDAAgD;IAChD,QAAQ,IAAI;IACZ,sDAAsD;IACtD,SAAS,IAAI;IACb,qDAAqD;IACrD,SAAS,IAAI;IACb,2DAA2D;IAC3D,QAAQ,KAAK;IACb,uDAAuD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