hazo_pdf 1.0.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 +21 -0
- package/README.md +56 -0
- package/dist/chunk-2POHPGR3.js +283 -0
- package/dist/chunk-2POHPGR3.js.map +1 -0
- package/dist/index.d.ts +593 -0
- package/dist/index.js +2815 -0
- package/dist/index.js.map +1 -0
- package/dist/pdf_saver-D2H5SLPN.js +12 -0
- package/dist/pdf_saver-D2H5SLPN.js.map +1 -0
- package/dist/styles/index.css +1789 -0
- package/dist/styles/index.css.map +1 -0
- package/package.json +94 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { PDFDocumentProxy, PDFPageProxy } from 'pdfjs-dist';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration types for hazo_pdf
|
|
6
|
+
* Defines all configurable styling values
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* PDF Viewer Configuration Interface
|
|
10
|
+
* Contains all configurable styling values organized by category
|
|
11
|
+
*/
|
|
12
|
+
interface PdfViewerConfig {
|
|
13
|
+
fonts: {
|
|
14
|
+
/** Font family for FreeText annotations */
|
|
15
|
+
freetext_font_family: string;
|
|
16
|
+
/** Minimum font size for FreeText annotations (in pixels) */
|
|
17
|
+
freetext_font_size_min: number;
|
|
18
|
+
/** Maximum font size for FreeText annotations (in pixels) */
|
|
19
|
+
freetext_font_size_max: number;
|
|
20
|
+
/** Default font size for FreeText annotations (in pixels) */
|
|
21
|
+
freetext_font_size_default: number;
|
|
22
|
+
/** Default font foreground (text) color for all text annotations (hex format: #RRGGBB or rgb(r, g, b)) */
|
|
23
|
+
font_foreground_color: string;
|
|
24
|
+
};
|
|
25
|
+
highlight_annotation: {
|
|
26
|
+
/** Fill color for highlight annotations (hex format) */
|
|
27
|
+
highlight_fill_color: string;
|
|
28
|
+
/** Fill opacity for highlight annotations (0.0 to 1.0) */
|
|
29
|
+
highlight_fill_opacity: number;
|
|
30
|
+
/** Border/stroke color for highlight annotations (hex format) */
|
|
31
|
+
highlight_border_color: string;
|
|
32
|
+
/** Border color on hover (hex format) */
|
|
33
|
+
highlight_border_color_hover: string;
|
|
34
|
+
/** Fill opacity on hover (0.0 to 1.0) */
|
|
35
|
+
highlight_fill_opacity_hover: number;
|
|
36
|
+
};
|
|
37
|
+
square_annotation: {
|
|
38
|
+
/** Fill color for square annotations (hex format) */
|
|
39
|
+
square_fill_color: string;
|
|
40
|
+
/** Fill opacity for square annotations (0.0 to 1.0) */
|
|
41
|
+
square_fill_opacity: number;
|
|
42
|
+
/** Border/stroke color for square annotations (hex format) */
|
|
43
|
+
square_border_color: string;
|
|
44
|
+
/** Border color on hover (hex format) */
|
|
45
|
+
square_border_color_hover: string;
|
|
46
|
+
/** Fill opacity on hover (0.0 to 1.0) */
|
|
47
|
+
square_fill_opacity_hover: number;
|
|
48
|
+
};
|
|
49
|
+
freetext_annotation: {
|
|
50
|
+
/** Text color for FreeText annotations (hex format) */
|
|
51
|
+
freetext_text_color: string;
|
|
52
|
+
/** Text color on hover (hex format) */
|
|
53
|
+
freetext_text_color_hover: string;
|
|
54
|
+
/** Border color for FreeText annotation box (hex format, empty string for no border) */
|
|
55
|
+
freetext_border_color: string;
|
|
56
|
+
/** Border width for FreeText annotation box (0 for no border) */
|
|
57
|
+
freetext_border_width: number;
|
|
58
|
+
/** Background color for FreeText annotation box (hex format, empty string for transparent) */
|
|
59
|
+
freetext_background_color: string;
|
|
60
|
+
/** Background opacity for FreeText annotation box (0.0 to 1.0, only used if background_color is set) */
|
|
61
|
+
freetext_background_opacity: number;
|
|
62
|
+
/** Font weight (normal, bold, etc.) */
|
|
63
|
+
freetext_font_weight: string;
|
|
64
|
+
/** Font style (normal, italic, etc.) */
|
|
65
|
+
freetext_font_style: string;
|
|
66
|
+
/** Text decoration (none, underline, line-through, etc.) */
|
|
67
|
+
freetext_text_decoration: string;
|
|
68
|
+
/** Horizontal padding inside the annotation box (left and right) in pixels */
|
|
69
|
+
freetext_padding_horizontal: number;
|
|
70
|
+
/** Vertical padding inside the annotation box (top and bottom) in pixels */
|
|
71
|
+
freetext_padding_vertical: number;
|
|
72
|
+
};
|
|
73
|
+
page_styling: {
|
|
74
|
+
/** Border color for PDF pages (hex format) */
|
|
75
|
+
page_border_color: string;
|
|
76
|
+
/** Box shadow CSS value for PDF pages */
|
|
77
|
+
page_box_shadow: string;
|
|
78
|
+
/** Background color for PDF pages (hex format) */
|
|
79
|
+
page_background_color: string;
|
|
80
|
+
};
|
|
81
|
+
viewer: {
|
|
82
|
+
/** Background color for PDF viewer area (hex format) */
|
|
83
|
+
viewer_background_color: string;
|
|
84
|
+
/** Whether to append timestamp to annotated text edits (default: false) */
|
|
85
|
+
/** When enabled, appends a newline followed by timestamp in format [YYYY-MM-DD h:mmam/pm] */
|
|
86
|
+
append_timestamp_to_text_edits: boolean;
|
|
87
|
+
/** Fixed text to add in square brackets before timestamp (default: empty) */
|
|
88
|
+
/** If provided and timestamp is enabled, format will be: text\n[fixed_text] [timestamp] */
|
|
89
|
+
annotation_text_suffix_fixed_text: string;
|
|
90
|
+
/** Whether to add enclosing brackets (default: true) */
|
|
91
|
+
add_enclosing_brackets_to_suffixes: boolean;
|
|
92
|
+
/** Enclosing bracket pair for suffixes (default: "[]", must be 2 characters) */
|
|
93
|
+
suffix_enclosing_brackets: string;
|
|
94
|
+
/** Placement of suffix text relative to input text (default: below_multi_line) */
|
|
95
|
+
/** Valid values: "adjacent", "below_single_line", "below_multi_line" */
|
|
96
|
+
suffix_text_position: 'adjacent' | 'below_single_line' | 'below_multi_line';
|
|
97
|
+
};
|
|
98
|
+
context_menu: {
|
|
99
|
+
/** Background color for context menu (hex format) */
|
|
100
|
+
context_menu_background_color: string;
|
|
101
|
+
/** Border color for context menu (hex format) */
|
|
102
|
+
context_menu_border_color: string;
|
|
103
|
+
/** Background color for context menu item on hover (hex format) */
|
|
104
|
+
context_menu_item_hover_background: string;
|
|
105
|
+
/** Opacity for disabled context menu items (0.0 to 1.0) */
|
|
106
|
+
context_menu_item_disabled_opacity: number;
|
|
107
|
+
/** Custom stamps for right-click menu (JSON array string) */
|
|
108
|
+
/** Each stamp has: name, text, order, time_stamp_suffix_enabled (default false), fixed_text_suffix_enabled (default false) */
|
|
109
|
+
/** Example: '[{"name":"Verified","text":"XXX","order":1,"time_stamp_suffix_enabled":true,"fixed_text_suffix_enabled":true}]' */
|
|
110
|
+
right_click_custom_stamps: string;
|
|
111
|
+
};
|
|
112
|
+
dialog: {
|
|
113
|
+
/** Opacity for dialog backdrop (0.0 to 1.0) */
|
|
114
|
+
dialog_backdrop_opacity: number;
|
|
115
|
+
/** Background color for dialog (hex format) */
|
|
116
|
+
dialog_background_color: string;
|
|
117
|
+
/** Border color for dialog (hex format) */
|
|
118
|
+
dialog_border_color: string;
|
|
119
|
+
/** Submit button color (hex format) */
|
|
120
|
+
dialog_button_submit_color: string;
|
|
121
|
+
/** Submit button color on hover (hex format) */
|
|
122
|
+
dialog_button_submit_color_hover: string;
|
|
123
|
+
/** Cancel button color (hex format) */
|
|
124
|
+
dialog_button_cancel_color: string;
|
|
125
|
+
/** Cancel button color on hover (hex format) */
|
|
126
|
+
dialog_button_cancel_color_hover: string;
|
|
127
|
+
/** Opacity for disabled dialog buttons (0.0 to 1.0) */
|
|
128
|
+
dialog_button_disabled_opacity: number;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Type definitions for hazo_pdf package
|
|
134
|
+
* Adheres to PDF annotation standard
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Props for the main PdfViewer component
|
|
139
|
+
*/
|
|
140
|
+
interface PdfViewerProps {
|
|
141
|
+
/** URL or path to the PDF file */
|
|
142
|
+
url: string;
|
|
143
|
+
/** Optional class name for styling */
|
|
144
|
+
className?: string;
|
|
145
|
+
/** Initial zoom level (default: 1.0) */
|
|
146
|
+
scale?: number;
|
|
147
|
+
/** Callback when PDF is loaded */
|
|
148
|
+
on_load?: (pdf: PDFDocumentProxy) => void;
|
|
149
|
+
/** Callback when an error occurs */
|
|
150
|
+
on_error?: (error: Error) => void;
|
|
151
|
+
/** Existing annotations to display */
|
|
152
|
+
annotations?: PdfAnnotation[];
|
|
153
|
+
/** Callback when annotation is created */
|
|
154
|
+
on_annotation_create?: (annotation: PdfAnnotation) => void;
|
|
155
|
+
/** Callback when annotation is updated */
|
|
156
|
+
on_annotation_update?: (annotation: PdfAnnotation) => void;
|
|
157
|
+
/** Callback when annotation is deleted */
|
|
158
|
+
on_annotation_delete?: (annotation_id: string) => void;
|
|
159
|
+
/** Callback when PDF is saved with annotations */
|
|
160
|
+
on_save?: (pdf_bytes: Uint8Array, filename: string) => void;
|
|
161
|
+
/** Background color for areas outside PDF pages (default: dark grey) */
|
|
162
|
+
background_color?: string;
|
|
163
|
+
/** Optional path to configuration INI file (e.g., "hazo_pdf_config.ini") */
|
|
164
|
+
config_file?: string;
|
|
165
|
+
/** Whether to append timestamp to annotated text edits (default: false) */
|
|
166
|
+
append_timestamp_to_text_edits?: boolean;
|
|
167
|
+
/** Fixed text to add in square brackets before timestamp (default: empty) */
|
|
168
|
+
/** If provided and timestamp is enabled, format will be: text\n[fixed_text] [timestamp] */
|
|
169
|
+
annotation_text_suffix_fixed_text?: string;
|
|
170
|
+
/** Custom stamps for right-click menu (JSON array string) */
|
|
171
|
+
/** Each stamp has: name, text, order, time_stamp_suffix_enabled (default false), fixed_text_suffix_enabled (default false) */
|
|
172
|
+
/** Example: '[{"name":"Verified","text":"XXX","order":1,"time_stamp_suffix_enabled":true,"fixed_text_suffix_enabled":true}]' */
|
|
173
|
+
right_click_custom_stamps?: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* PDF Annotation interface matching PDF standard
|
|
177
|
+
* Uses PDF coordinate space (rect as [x1, y1, x2, y2])
|
|
178
|
+
*/
|
|
179
|
+
interface PdfAnnotation {
|
|
180
|
+
/** Unique identifier for the annotation */
|
|
181
|
+
id: string;
|
|
182
|
+
/** Type of annotation following PDF standard */
|
|
183
|
+
type: 'Highlight' | 'Square' | 'FreeText' | 'CustomBookmark';
|
|
184
|
+
/** Zero-based page index */
|
|
185
|
+
page_index: number;
|
|
186
|
+
/** Rectangle coordinates in PDF space [x1, y1, x2, y2] */
|
|
187
|
+
rect: [number, number, number, number];
|
|
188
|
+
/** Author of the annotation */
|
|
189
|
+
author: string;
|
|
190
|
+
/** Creation/modification date in ISO format */
|
|
191
|
+
date: string;
|
|
192
|
+
/** Text content or comment */
|
|
193
|
+
contents: string;
|
|
194
|
+
/** Color in hex format (e.g., "#FF0000") */
|
|
195
|
+
color?: string;
|
|
196
|
+
/** Subject/title of the annotation */
|
|
197
|
+
subject?: string;
|
|
198
|
+
/** Flags for annotation behavior */
|
|
199
|
+
flags?: string;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* PDF Bookmark/Outline interface
|
|
203
|
+
*/
|
|
204
|
+
interface PdfBookmark {
|
|
205
|
+
/** Unique identifier */
|
|
206
|
+
id: string;
|
|
207
|
+
/** Title of the bookmark */
|
|
208
|
+
title: string;
|
|
209
|
+
/** Page index this bookmark points to */
|
|
210
|
+
page_index: number;
|
|
211
|
+
/** Y coordinate on the page */
|
|
212
|
+
y?: number;
|
|
213
|
+
/** Action type */
|
|
214
|
+
action?: string;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Custom stamp configuration for right-click menu
|
|
218
|
+
*/
|
|
219
|
+
interface CustomStamp {
|
|
220
|
+
/** Name of the stamp (displayed as menu item) */
|
|
221
|
+
name: string;
|
|
222
|
+
/** Text content to add to PDF */
|
|
223
|
+
text: string;
|
|
224
|
+
/** Order/position in menu (lower numbers appear first) */
|
|
225
|
+
order: number;
|
|
226
|
+
/** Whether to append timestamp suffix (default: false) */
|
|
227
|
+
time_stamp_suffix_enabled?: boolean;
|
|
228
|
+
/** Whether to append fixed text suffix (default: false) */
|
|
229
|
+
fixed_text_suffix_enabled?: boolean;
|
|
230
|
+
/** Background color for the annotation box (hex format: #RRGGBB or rgb(r, g, b), empty string for transparent) */
|
|
231
|
+
background_color?: string;
|
|
232
|
+
/** Border size/width in pixels (0 means no border, default: uses config default) */
|
|
233
|
+
border_size?: number;
|
|
234
|
+
/** Font color for the text (hex format: #RRGGBB or rgb(r, g, b), default: uses config default) */
|
|
235
|
+
font_color?: string;
|
|
236
|
+
/** Font weight (normal, bold, etc., default: uses config default) */
|
|
237
|
+
font_weight?: string;
|
|
238
|
+
/** Font style (normal, italic, etc., default: uses config default) */
|
|
239
|
+
font_style?: string;
|
|
240
|
+
/** Font size in pixels (default: uses config default) */
|
|
241
|
+
font_size?: number;
|
|
242
|
+
/** Font family/name (e.g., "Arial, sans-serif", default: uses config default) */
|
|
243
|
+
font_name?: string;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Coordinate mapping utilities
|
|
247
|
+
* Converts between PDF space and Screen space
|
|
248
|
+
*/
|
|
249
|
+
interface CoordinateMapper {
|
|
250
|
+
/** Convert screen coordinates to PDF coordinates */
|
|
251
|
+
to_pdf: (x_screen: number, y_screen: number) => [number, number];
|
|
252
|
+
/** Convert PDF coordinates to screen coordinates */
|
|
253
|
+
to_screen: (x_pdf: number, y_pdf: number) => [number, number];
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Page dimensions in screen space
|
|
257
|
+
*/
|
|
258
|
+
interface PageDimensions {
|
|
259
|
+
width: number;
|
|
260
|
+
height: number;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* PDF Document Proxy type
|
|
264
|
+
*/
|
|
265
|
+
type PdfDocument = PDFDocumentProxy;
|
|
266
|
+
/**
|
|
267
|
+
* PDF Page Proxy type
|
|
268
|
+
*/
|
|
269
|
+
type PdfPage = PDFPageProxy;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* PDF Viewer Component
|
|
273
|
+
* Main component for displaying and interacting with PDF documents
|
|
274
|
+
* Integrates PDF rendering, annotation overlay, and layout management
|
|
275
|
+
*/
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* PDF Viewer Component
|
|
279
|
+
* Main entry point for PDF viewing and annotation
|
|
280
|
+
*/
|
|
281
|
+
declare const PdfViewer: React.FC<PdfViewerProps>;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* PDF Viewer Layout Component
|
|
285
|
+
* Main layout container with scrollable viewport
|
|
286
|
+
* Manages page rendering and annotation overlay
|
|
287
|
+
*/
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Props for PdfViewerLayout component
|
|
291
|
+
*/
|
|
292
|
+
interface PdfViewerLayoutProps {
|
|
293
|
+
pdf_document: PDFDocumentProxy;
|
|
294
|
+
scale: number;
|
|
295
|
+
annotations: PdfAnnotation[];
|
|
296
|
+
current_tool: 'Square' | 'Highlight' | 'FreeText' | 'CustomBookmark' | null;
|
|
297
|
+
on_annotation_create: (annotation: PdfAnnotation) => void;
|
|
298
|
+
on_context_menu: (e: React.MouseEvent, page_index: number, screen_x: number, screen_y: number, mapper: CoordinateMapper) => void;
|
|
299
|
+
on_annotation_click: (annotation: PdfAnnotation, screen_x: number, screen_y: number, mapper: CoordinateMapper) => void;
|
|
300
|
+
background_color?: string;
|
|
301
|
+
config: PdfViewerConfig | null;
|
|
302
|
+
className?: string;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* PDF Viewer Layout Component
|
|
306
|
+
* Manages page rendering and annotation overlay coordination
|
|
307
|
+
*/
|
|
308
|
+
declare const PdfViewerLayout: React.FC<PdfViewerLayoutProps>;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* PDF Page Renderer Component
|
|
312
|
+
* Renders a single PDF page to a canvas element
|
|
313
|
+
* Provides coordinate mapping utilities for annotations
|
|
314
|
+
*/
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Props for PDFPageRenderer component
|
|
318
|
+
*/
|
|
319
|
+
interface PdfPageRendererProps {
|
|
320
|
+
/** PDF page proxy object */
|
|
321
|
+
page: PDFPageProxy;
|
|
322
|
+
/** Zero-based page index */
|
|
323
|
+
page_index: number;
|
|
324
|
+
/** Zoom/scale factor */
|
|
325
|
+
scale: number;
|
|
326
|
+
/** Optional class name */
|
|
327
|
+
className?: string;
|
|
328
|
+
/** Callback to provide coordinate mapper to parent */
|
|
329
|
+
on_coordinate_mapper_ready?: (mapper: CoordinateMapper, dimensions: PageDimensions) => void;
|
|
330
|
+
/** Configuration object for styling */
|
|
331
|
+
config?: PdfViewerConfig | null;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* PDF Page Renderer Component
|
|
335
|
+
* Handles rendering of a single PDF page to canvas
|
|
336
|
+
*/
|
|
337
|
+
declare const PdfPageRenderer: React.FC<PdfPageRendererProps>;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Annotation Overlay Component
|
|
341
|
+
* DOM/SVG layer for handling annotation interactions
|
|
342
|
+
* Positioned above the canvas layer
|
|
343
|
+
*/
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Props for AnnotationOverlay component
|
|
347
|
+
*/
|
|
348
|
+
interface AnnotationOverlayProps {
|
|
349
|
+
/** Page dimensions in screen space */
|
|
350
|
+
width: number;
|
|
351
|
+
height: number;
|
|
352
|
+
/** Zero-based page index */
|
|
353
|
+
page_index: number;
|
|
354
|
+
/** Coordinate mapper for PDF ↔ Screen conversion */
|
|
355
|
+
map_coords: CoordinateMapper;
|
|
356
|
+
/** Existing annotations for this page */
|
|
357
|
+
annotations?: PdfAnnotation[];
|
|
358
|
+
/** Current annotation tool type */
|
|
359
|
+
current_tool?: 'Square' | 'Highlight' | 'FreeText' | 'CustomBookmark' | null;
|
|
360
|
+
/** Callback when annotation is created */
|
|
361
|
+
on_annotation_create?: (annotation: PdfAnnotation) => void;
|
|
362
|
+
/** Callback when right-click occurs */
|
|
363
|
+
on_context_menu?: (event: React.MouseEvent, screen_x: number, screen_y: number) => void;
|
|
364
|
+
/** Callback when annotation is clicked */
|
|
365
|
+
on_annotation_click?: (annotation: PdfAnnotation, screen_x: number, screen_y: number) => void;
|
|
366
|
+
/** Configuration object for styling */
|
|
367
|
+
config?: PdfViewerConfig | null;
|
|
368
|
+
/** Optional class name */
|
|
369
|
+
className?: string;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Annotation Overlay Component
|
|
373
|
+
* Handles mouse interactions for creating annotations
|
|
374
|
+
*/
|
|
375
|
+
declare const AnnotationOverlay: React.FC<AnnotationOverlayProps>;
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* PDF Worker Setup
|
|
379
|
+
* Configures pdfjs-dist to use Web Workers for PDF processing
|
|
380
|
+
* This ensures PDF parsing and rendering happens off the main thread
|
|
381
|
+
*
|
|
382
|
+
* IMPORTANT: This module uses dynamic imports to prevent SSR evaluation
|
|
383
|
+
* PDF.js can only run in the browser, so we must avoid importing it during SSR
|
|
384
|
+
*/
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Load a PDF document from a URL or ArrayBuffer
|
|
388
|
+
* For local files (like in Storybook), fetch as ArrayBuffer for better compatibility
|
|
389
|
+
* @param source - URL string, ArrayBuffer, or Uint8Array
|
|
390
|
+
* @returns Promise resolving to PDFDocumentProxy
|
|
391
|
+
*/
|
|
392
|
+
declare function load_pdf_document(source: string | ArrayBuffer | Uint8Array): Promise<PDFDocumentProxy>;
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* XFDF Generator Utility
|
|
396
|
+
* Converts annotation and bookmark data to XFDF (XML Forms Data Format)
|
|
397
|
+
* XFDF is the standard format for PDF annotations
|
|
398
|
+
*/
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Generate XFDF XML from annotations and bookmarks
|
|
402
|
+
* @param annotations - Array of annotations
|
|
403
|
+
* @param bookmarks - Array of bookmarks (optional)
|
|
404
|
+
* @param pdf_file_name - Name of the PDF file
|
|
405
|
+
* @returns XFDF XML string
|
|
406
|
+
*/
|
|
407
|
+
declare function generate_xfdf(annotations: PdfAnnotation[], bookmarks?: PdfBookmark[], pdf_file_name?: string): string;
|
|
408
|
+
/**
|
|
409
|
+
* Download XFDF file
|
|
410
|
+
* @param xfdf_content - XFDF XML content
|
|
411
|
+
* @param file_name - Name for the downloaded file
|
|
412
|
+
*/
|
|
413
|
+
declare function download_xfdf(xfdf_content: string, file_name?: string): void;
|
|
414
|
+
/**
|
|
415
|
+
* Generate and download XFDF file
|
|
416
|
+
* @param annotations - Array of annotations
|
|
417
|
+
* @param bookmarks - Array of bookmarks (optional)
|
|
418
|
+
* @param pdf_file_name - Name of the PDF file
|
|
419
|
+
* @param file_name - Name for the downloaded file
|
|
420
|
+
*/
|
|
421
|
+
declare function export_annotations_to_xfdf(annotations: PdfAnnotation[], bookmarks?: PdfBookmark[], pdf_file_name?: string, file_name?: string): void;
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* PDF Saver Utility
|
|
425
|
+
* Saves annotations directly into PDF documents using pdf-lib
|
|
426
|
+
* This allows annotations to be embedded in the PDF file itself
|
|
427
|
+
*/
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Save annotations into a PDF document
|
|
431
|
+
* This function fetches the PDF, adds annotations, and downloads the modified PDF
|
|
432
|
+
* @param pdf_url - URL of the PDF file
|
|
433
|
+
* @param annotations - Array of annotations to save
|
|
434
|
+
* @param output_filename - Name for the saved PDF file (default: original filename with '_annotated' suffix)
|
|
435
|
+
* @param config - Optional configuration for styling values
|
|
436
|
+
* @returns Promise that resolves when the PDF is saved
|
|
437
|
+
*/
|
|
438
|
+
declare function save_annotations_to_pdf(pdf_url: string, annotations: PdfAnnotation[], _output_filename?: string, // Currently unused, kept for API compatibility
|
|
439
|
+
config?: PdfViewerConfig | null): Promise<Uint8Array>;
|
|
440
|
+
/**
|
|
441
|
+
* Download PDF bytes as a file
|
|
442
|
+
* @param pdf_bytes - PDF file bytes
|
|
443
|
+
* @param filename - Name for the downloaded file
|
|
444
|
+
*/
|
|
445
|
+
declare function download_pdf(pdf_bytes: Uint8Array, filename: string): void;
|
|
446
|
+
/**
|
|
447
|
+
* Save annotations to PDF and download
|
|
448
|
+
* @param pdf_url - URL of the PDF file
|
|
449
|
+
* @param annotations - Array of annotations to save
|
|
450
|
+
* @param output_filename - Name for the saved PDF file (default: original filename with '_annotated' suffix)
|
|
451
|
+
* @param config - Optional configuration for styling values
|
|
452
|
+
*/
|
|
453
|
+
declare function save_and_download_pdf(pdf_url: string, annotations: PdfAnnotation[], output_filename?: string, config?: PdfViewerConfig | null): Promise<void>;
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Coordinate Mapper Utilities
|
|
457
|
+
* Handles conversion between PDF coordinate space and Screen coordinate space
|
|
458
|
+
* PDF coordinates use bottom-left origin, Screen coordinates use top-left origin
|
|
459
|
+
*/
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Create a coordinate mapper for a specific page and scale
|
|
463
|
+
* @param page - PDF page proxy
|
|
464
|
+
* @param scale - Zoom/scale factor
|
|
465
|
+
* @returns CoordinateMapper with to_pdf and to_screen methods
|
|
466
|
+
*/
|
|
467
|
+
declare function create_coordinate_mapper(page: PDFPageProxy, scale: number): CoordinateMapper;
|
|
468
|
+
/**
|
|
469
|
+
* Get viewport dimensions for a page at a specific scale
|
|
470
|
+
* @param page - PDF page proxy
|
|
471
|
+
* @param scale - Zoom/scale factor
|
|
472
|
+
* @returns Object with width and height in screen pixels
|
|
473
|
+
*/
|
|
474
|
+
declare function get_viewport_dimensions(page: PDFPageProxy, scale: number): {
|
|
475
|
+
width: number;
|
|
476
|
+
height: number;
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Annotation Utility Functions
|
|
481
|
+
* Helper functions for annotation calculations and transformations
|
|
482
|
+
*/
|
|
483
|
+
/**
|
|
484
|
+
* Point coordinates
|
|
485
|
+
*/
|
|
486
|
+
interface Point {
|
|
487
|
+
x: number;
|
|
488
|
+
y: number;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Rectangle coordinates (normalized)
|
|
492
|
+
*/
|
|
493
|
+
interface Rectangle {
|
|
494
|
+
x: number;
|
|
495
|
+
y: number;
|
|
496
|
+
width: number;
|
|
497
|
+
height: number;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Calculates a normalized rectangle bounding box (x, y, width, height)
|
|
501
|
+
* given any two diagonal points
|
|
502
|
+
* @param p1 - First point
|
|
503
|
+
* @param p2 - Second point
|
|
504
|
+
* @returns Normalized rectangle with top-left origin
|
|
505
|
+
*/
|
|
506
|
+
declare function calculate_rectangle_coords(p1: Point, p2: Point): Rectangle;
|
|
507
|
+
/**
|
|
508
|
+
* Convert rectangle to PDF rect format [x1, y1, x2, y2]
|
|
509
|
+
* @param rect - Rectangle with x, y, width, height
|
|
510
|
+
* @returns PDF rect array [x1, y1, x2, y2]
|
|
511
|
+
*/
|
|
512
|
+
declare function rectangle_to_pdf_rect(rect: Rectangle): [number, number, number, number];
|
|
513
|
+
/**
|
|
514
|
+
* Convert PDF rect format [x1, y1, x2, y2] to rectangle
|
|
515
|
+
* @param pdf_rect - PDF rect array [x1, y1, x2, y2]
|
|
516
|
+
* @returns Rectangle with x, y, width, height
|
|
517
|
+
*/
|
|
518
|
+
declare function pdf_rect_to_rectangle(pdf_rect: [number, number, number, number]): Rectangle;
|
|
519
|
+
/**
|
|
520
|
+
* Check if a rectangle is too small (likely a click, not a drag)
|
|
521
|
+
* @param rect - Rectangle to check
|
|
522
|
+
* @param min_size - Minimum size in pixels (default: 5)
|
|
523
|
+
* @returns True if rectangle is too small
|
|
524
|
+
*/
|
|
525
|
+
declare function is_rectangle_too_small(rect: Rectangle, min_size?: number): boolean;
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Configuration loader for hazo_pdf
|
|
529
|
+
* Loads configuration from INI file using hazo_config package (Node.js) or fetch (browser)
|
|
530
|
+
* Falls back to defaults if config file is missing or invalid
|
|
531
|
+
*/
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Load config asynchronously (works in both browser and Node.js)
|
|
535
|
+
* Uses hazo_config in Node.js, fetch + manual parsing in browser
|
|
536
|
+
* @param config_file - Path to config file
|
|
537
|
+
* @returns Promise resolving to PdfViewerConfig
|
|
538
|
+
*/
|
|
539
|
+
declare function load_pdf_config_async(config_file: string): Promise<PdfViewerConfig>;
|
|
540
|
+
/**
|
|
541
|
+
* Build config object from INI values (shared between browser and Node.js)
|
|
542
|
+
* @param get_value - Function to get a value from INI (section, key) -> value
|
|
543
|
+
* @returns Complete PdfViewerConfig object
|
|
544
|
+
*/
|
|
545
|
+
declare function build_config_from_ini(get_value: (section: string, key: string) => string | undefined): PdfViewerConfig;
|
|
546
|
+
/**
|
|
547
|
+
* Parse a color value from config (hex format)
|
|
548
|
+
* @param value - Color value from config
|
|
549
|
+
* @param default_value - Default color if parsing fails
|
|
550
|
+
* @returns Parsed color value
|
|
551
|
+
*/
|
|
552
|
+
declare function parse_color(value: string | undefined, default_value: string): string;
|
|
553
|
+
/**
|
|
554
|
+
* Parse an opacity value from config (0.0 to 1.0)
|
|
555
|
+
* @param value - Opacity value from config
|
|
556
|
+
* @param default_value - Default opacity if parsing fails
|
|
557
|
+
* @returns Parsed opacity value
|
|
558
|
+
*/
|
|
559
|
+
declare function parse_opacity(value: string | undefined, default_value: number): number;
|
|
560
|
+
/**
|
|
561
|
+
* Parse a number value from config
|
|
562
|
+
* @param value - Number value from config
|
|
563
|
+
* @param default_value - Default number if parsing fails
|
|
564
|
+
* @returns Parsed number value
|
|
565
|
+
*/
|
|
566
|
+
declare function parse_number(value: string | undefined, default_value: number): number;
|
|
567
|
+
/**
|
|
568
|
+
* Parse a string value from config
|
|
569
|
+
* @param value - String value from config
|
|
570
|
+
* @param default_value - Default string if value is missing
|
|
571
|
+
* @returns Parsed string value
|
|
572
|
+
*/
|
|
573
|
+
declare function parse_string(value: string | undefined, default_value: string): string;
|
|
574
|
+
/**
|
|
575
|
+
* Load PDF viewer configuration from INI file
|
|
576
|
+
* Supports both Node.js (using hazo_config) and browser (using fetch) environments
|
|
577
|
+
* @param config_file - Optional path to config file. If not provided, returns defaults
|
|
578
|
+
* @returns Configuration object with loaded values merged with defaults
|
|
579
|
+
*/
|
|
580
|
+
declare function load_pdf_config(config_file?: string): PdfViewerConfig;
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Default configuration values for hazo_pdf
|
|
584
|
+
* All styling defaults organized by category
|
|
585
|
+
*/
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Default PDF Viewer Configuration
|
|
589
|
+
* These values are used when no config file is provided or when values are missing
|
|
590
|
+
*/
|
|
591
|
+
declare const default_config: PdfViewerConfig;
|
|
592
|
+
|
|
593
|
+
export { AnnotationOverlay, type CoordinateMapper, type CustomStamp, type PageDimensions, type PdfAnnotation, type PdfBookmark, type PdfDocument, type PdfPage, PdfPageRenderer, PdfViewer, type PdfViewerConfig, PdfViewerLayout, type PdfViewerProps, build_config_from_ini, calculate_rectangle_coords, create_coordinate_mapper, default_config, download_pdf, download_xfdf, export_annotations_to_xfdf, generate_xfdf, get_viewport_dimensions, is_rectangle_too_small, load_pdf_config, load_pdf_config_async, load_pdf_document, parse_color, parse_number, parse_opacity, parse_string, pdf_rect_to_rectangle, rectangle_to_pdf_rect, save_and_download_pdf, save_annotations_to_pdf };
|