pdf-oxide-fips 0.3.47

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.
Files changed (127) hide show
  1. package/LICENSE-APACHE +176 -0
  2. package/LICENSE-MIT +25 -0
  3. package/README.md +218 -0
  4. package/lib/builders/annotation-builder.d.ts +198 -0
  5. package/lib/builders/annotation-builder.js +317 -0
  6. package/lib/builders/conversion-options-builder.d.ts +106 -0
  7. package/lib/builders/conversion-options-builder.js +214 -0
  8. package/lib/builders/document-builder.d.ts +381 -0
  9. package/lib/builders/document-builder.js +770 -0
  10. package/lib/builders/index.d.ts +13 -0
  11. package/lib/builders/index.js +13 -0
  12. package/lib/builders/metadata-builder.d.ts +201 -0
  13. package/lib/builders/metadata-builder.js +285 -0
  14. package/lib/builders/pdf-builder.d.ts +216 -0
  15. package/lib/builders/pdf-builder.js +350 -0
  16. package/lib/builders/search-options-builder.d.ts +73 -0
  17. package/lib/builders/search-options-builder.js +129 -0
  18. package/lib/builders/streaming-table.d.ts +64 -0
  19. package/lib/builders/streaming-table.js +140 -0
  20. package/lib/document-editor-manager.d.ts +139 -0
  21. package/lib/document-editor-manager.js +256 -0
  22. package/lib/document-editor.d.ts +124 -0
  23. package/lib/document-editor.js +318 -0
  24. package/lib/errors.d.ts +382 -0
  25. package/lib/errors.js +1115 -0
  26. package/lib/form-field-manager.d.ts +299 -0
  27. package/lib/form-field-manager.js +568 -0
  28. package/lib/hybrid-ml-manager.d.ts +142 -0
  29. package/lib/hybrid-ml-manager.js +208 -0
  30. package/lib/index.d.ts +205 -0
  31. package/lib/index.js +693 -0
  32. package/lib/managers/accessibility-manager.d.ts +148 -0
  33. package/lib/managers/accessibility-manager.js +234 -0
  34. package/lib/managers/annotation-manager.d.ts +219 -0
  35. package/lib/managers/annotation-manager.js +359 -0
  36. package/lib/managers/barcode-manager.d.ts +82 -0
  37. package/lib/managers/barcode-manager.js +263 -0
  38. package/lib/managers/batch-manager.d.ts +185 -0
  39. package/lib/managers/batch-manager.js +385 -0
  40. package/lib/managers/cache-manager.d.ts +181 -0
  41. package/lib/managers/cache-manager.js +384 -0
  42. package/lib/managers/compliance-manager.d.ts +103 -0
  43. package/lib/managers/compliance-manager.js +453 -0
  44. package/lib/managers/content-manager.d.ts +120 -0
  45. package/lib/managers/content-manager.js +294 -0
  46. package/lib/managers/document-utility-manager.d.ts +369 -0
  47. package/lib/managers/document-utility-manager.js +730 -0
  48. package/lib/managers/dom-pdf-creator.d.ts +104 -0
  49. package/lib/managers/dom-pdf-creator.js +299 -0
  50. package/lib/managers/editing-manager.d.ts +248 -0
  51. package/lib/managers/editing-manager.js +387 -0
  52. package/lib/managers/enterprise-manager.d.ts +192 -0
  53. package/lib/managers/enterprise-manager.js +307 -0
  54. package/lib/managers/extended-managers.d.ts +122 -0
  55. package/lib/managers/extended-managers.js +664 -0
  56. package/lib/managers/extraction-manager.d.ts +246 -0
  57. package/lib/managers/extraction-manager.js +482 -0
  58. package/lib/managers/final-utilities.d.ts +127 -0
  59. package/lib/managers/final-utilities.js +657 -0
  60. package/lib/managers/hybrid-ml-advanced.d.ts +136 -0
  61. package/lib/managers/hybrid-ml-advanced.js +722 -0
  62. package/lib/managers/index.d.ts +64 -0
  63. package/lib/managers/index.js +69 -0
  64. package/lib/managers/layer-manager.d.ts +203 -0
  65. package/lib/managers/layer-manager.js +401 -0
  66. package/lib/managers/metadata-manager.d.ts +148 -0
  67. package/lib/managers/metadata-manager.js +280 -0
  68. package/lib/managers/ocr-manager.d.ts +194 -0
  69. package/lib/managers/ocr-manager.js +582 -0
  70. package/lib/managers/optimization-manager.d.ts +102 -0
  71. package/lib/managers/optimization-manager.js +213 -0
  72. package/lib/managers/outline-manager.d.ts +101 -0
  73. package/lib/managers/outline-manager.js +169 -0
  74. package/lib/managers/page-manager.d.ts +142 -0
  75. package/lib/managers/page-manager.js +235 -0
  76. package/lib/managers/pattern-detection.d.ts +169 -0
  77. package/lib/managers/pattern-detection.js +322 -0
  78. package/lib/managers/rendering-manager.d.ts +353 -0
  79. package/lib/managers/rendering-manager.js +679 -0
  80. package/lib/managers/search-manager.d.ts +235 -0
  81. package/lib/managers/search-manager.js +329 -0
  82. package/lib/managers/security-manager.d.ts +161 -0
  83. package/lib/managers/security-manager.js +292 -0
  84. package/lib/managers/signature-manager.d.ts +738 -0
  85. package/lib/managers/signature-manager.js +1509 -0
  86. package/lib/managers/streams.d.ts +262 -0
  87. package/lib/managers/streams.js +477 -0
  88. package/lib/managers/xfa-manager.d.ts +227 -0
  89. package/lib/managers/xfa-manager.js +539 -0
  90. package/lib/native-loader.d.ts +7 -0
  91. package/lib/native-loader.js +62 -0
  92. package/lib/native.d.ts +16 -0
  93. package/lib/native.js +69 -0
  94. package/lib/pdf-creator-manager.d.ts +200 -0
  95. package/lib/pdf-creator-manager.js +381 -0
  96. package/lib/properties.d.ts +79 -0
  97. package/lib/properties.js +454 -0
  98. package/lib/result-accessors-manager.d.ts +346 -0
  99. package/lib/result-accessors-manager.js +706 -0
  100. package/lib/thumbnail-manager.d.ts +121 -0
  101. package/lib/thumbnail-manager.js +205 -0
  102. package/lib/timestamp.d.ts +54 -0
  103. package/lib/timestamp.js +115 -0
  104. package/lib/tsa-client.d.ts +44 -0
  105. package/lib/tsa-client.js +67 -0
  106. package/lib/types/common.d.ts +189 -0
  107. package/lib/types/common.js +17 -0
  108. package/lib/types/document-types.d.ts +352 -0
  109. package/lib/types/document-types.js +82 -0
  110. package/lib/types/index.d.ts +5 -0
  111. package/lib/types/index.js +5 -0
  112. package/lib/types/manager-types.d.ts +179 -0
  113. package/lib/types/manager-types.js +100 -0
  114. package/lib/types/native-bindings.d.ts +439 -0
  115. package/lib/types/native-bindings.js +7 -0
  116. package/lib/workers/index.d.ts +6 -0
  117. package/lib/workers/index.js +5 -0
  118. package/lib/workers/pool.d.ts +64 -0
  119. package/lib/workers/pool.js +192 -0
  120. package/lib/workers/worker.d.ts +5 -0
  121. package/lib/workers/worker.js +99 -0
  122. package/package.json +79 -0
  123. package/prebuilds/darwin-arm64/pdf_oxide.node +0 -0
  124. package/prebuilds/darwin-x64/pdf_oxide.node +0 -0
  125. package/prebuilds/linux-arm64/pdf_oxide.node +0 -0
  126. package/prebuilds/linux-x64/pdf_oxide.node +0 -0
  127. package/prebuilds/win32-x64/pdf_oxide.node +0 -0
@@ -0,0 +1,213 @@
1
+ /**
2
+ * OptimizationManager - PDF Optimization Operations
3
+ *
4
+ * Provides document optimization capabilities including:
5
+ * - Font subsetting
6
+ * - Image downsampling
7
+ * - Object deduplication
8
+ * - Full optimization pipeline
9
+ *
10
+ * @since 1.0.0
11
+ */
12
+ import { EventEmitter } from 'events';
13
+ import { mapFfiErrorCode, OptimizationException } from '../errors.js';
14
+ // =============================================================================
15
+ // OptimizationManager
16
+ // =============================================================================
17
+ /**
18
+ * Manager for PDF optimization operations.
19
+ *
20
+ * Provides methods for reducing PDF file size through font subsetting,
21
+ * image downsampling, object deduplication, and combined optimization.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const optimizer = new OptimizationManager(document);
26
+ *
27
+ * // Subset fonts to remove unused glyphs
28
+ * const fontResult = await optimizer.subsetFonts();
29
+ * console.log(`Font subsetting saved ${fontResult.bytesSaved} bytes`);
30
+ *
31
+ * // Downsample high-resolution images
32
+ * const imageResult = await optimizer.downsampleImages(150, 80);
33
+ *
34
+ * // Full optimization pipeline
35
+ * const fullResult = await optimizer.optimizeFull(150, 80);
36
+ * console.log(`Total savings: ${fullResult.bytesSaved} bytes`);
37
+ * ```
38
+ */
39
+ export class OptimizationManager extends EventEmitter {
40
+ constructor(document) {
41
+ super();
42
+ if (!document) {
43
+ throw new Error('Document cannot be null or undefined');
44
+ }
45
+ this.document = document;
46
+ try {
47
+ this.native = require('../../index.node');
48
+ }
49
+ catch {
50
+ this.native = null;
51
+ }
52
+ }
53
+ // ===========================================================================
54
+ // Optimization Operations
55
+ // ===========================================================================
56
+ /**
57
+ * Subsets all embedded fonts in the document.
58
+ *
59
+ * Removes unused glyphs from embedded fonts, reducing file size
60
+ * while preserving visual fidelity for the characters actually used.
61
+ *
62
+ * @returns Optimization result with bytes saved
63
+ * @throws OptimizationException if the operation fails
64
+ */
65
+ async subsetFonts() {
66
+ if (!this.native?.pdf_optimize_subset_fonts) {
67
+ throw new OptimizationException('Native optimization not available: pdf_optimize_subset_fonts not found');
68
+ }
69
+ const errorCode = Buffer.alloc(4);
70
+ const resultPtr = this.native.pdf_optimize_subset_fonts(this.document._handle ?? this.document, errorCode);
71
+ const code = errorCode.readInt32LE(0);
72
+ if (code !== 0) {
73
+ throw mapFfiErrorCode(code, 'Failed to subset fonts');
74
+ }
75
+ const result = this.parseOptimizationResult(resultPtr);
76
+ this.emit('fonts-subsetted', { bytesSaved: result.bytesSaved });
77
+ this.freeOptimizationResult(resultPtr);
78
+ return result;
79
+ }
80
+ /**
81
+ * Downsamples images in the document to reduce file size.
82
+ *
83
+ * @param dpi - Target resolution in dots per inch (default: 150)
84
+ * @param quality - JPEG quality for recompression (1-100, default: 80)
85
+ * @returns Optimization result with bytes saved
86
+ * @throws OptimizationException if the operation fails
87
+ */
88
+ async downsampleImages(dpi, quality) {
89
+ if (!this.native?.pdf_optimize_downsample_images) {
90
+ throw new OptimizationException('Native optimization not available: pdf_optimize_downsample_images not found');
91
+ }
92
+ const errorCode = Buffer.alloc(4);
93
+ const resultPtr = this.native.pdf_optimize_downsample_images(this.document._handle ?? this.document, dpi ?? 150, quality ?? 80, errorCode);
94
+ const code = errorCode.readInt32LE(0);
95
+ if (code !== 0) {
96
+ throw mapFfiErrorCode(code, 'Failed to downsample images');
97
+ }
98
+ const result = this.parseOptimizationResult(resultPtr);
99
+ this.emit('images-downsampled', {
100
+ dpi: dpi ?? 150,
101
+ quality: quality ?? 80,
102
+ bytesSaved: result.bytesSaved,
103
+ });
104
+ this.freeOptimizationResult(resultPtr);
105
+ return result;
106
+ }
107
+ /**
108
+ * Deduplicates identical objects in the document.
109
+ *
110
+ * Identifies and merges duplicate fonts, images, and other resources
111
+ * that appear multiple times in the document.
112
+ *
113
+ * @returns Optimization result with bytes saved
114
+ * @throws OptimizationException if the operation fails
115
+ */
116
+ async deduplicate() {
117
+ if (!this.native?.pdf_optimize_deduplicate) {
118
+ throw new OptimizationException('Native optimization not available: pdf_optimize_deduplicate not found');
119
+ }
120
+ const errorCode = Buffer.alloc(4);
121
+ const resultPtr = this.native.pdf_optimize_deduplicate(this.document._handle ?? this.document, errorCode);
122
+ const code = errorCode.readInt32LE(0);
123
+ if (code !== 0) {
124
+ throw mapFfiErrorCode(code, 'Failed to deduplicate objects');
125
+ }
126
+ const result = this.parseOptimizationResult(resultPtr);
127
+ this.emit('deduplicated', { bytesSaved: result.bytesSaved });
128
+ this.freeOptimizationResult(resultPtr);
129
+ return result;
130
+ }
131
+ /**
132
+ * Runs the full optimization pipeline.
133
+ *
134
+ * Combines font subsetting, image downsampling, and object deduplication
135
+ * into a single operation for maximum file size reduction.
136
+ *
137
+ * @param dpi - Target image resolution in dots per inch (default: 150)
138
+ * @param quality - JPEG quality for recompression (1-100, default: 80)
139
+ * @returns Optimization result with total bytes saved
140
+ * @throws OptimizationException if the operation fails
141
+ */
142
+ async optimizeFull(dpi, quality) {
143
+ if (!this.native?.pdf_optimize_full) {
144
+ throw new OptimizationException('Native optimization not available: pdf_optimize_full not found');
145
+ }
146
+ const errorCode = Buffer.alloc(4);
147
+ const resultPtr = this.native.pdf_optimize_full(this.document._handle ?? this.document, dpi ?? 150, quality ?? 80, errorCode);
148
+ const code = errorCode.readInt32LE(0);
149
+ if (code !== 0) {
150
+ throw mapFfiErrorCode(code, 'Failed to run full optimization');
151
+ }
152
+ const result = this.parseOptimizationResult(resultPtr);
153
+ this.emit('optimized-full', {
154
+ dpi: dpi ?? 150,
155
+ quality: quality ?? 80,
156
+ bytesSaved: result.bytesSaved,
157
+ });
158
+ this.freeOptimizationResult(resultPtr);
159
+ return result;
160
+ }
161
+ // ===========================================================================
162
+ // Private Helpers
163
+ // ===========================================================================
164
+ parseOptimizationResult(resultPtr) {
165
+ if (!resultPtr) {
166
+ return {
167
+ success: true,
168
+ bytesSaved: 0,
169
+ originalSize: 0,
170
+ optimizedSize: 0,
171
+ compressionRatio: 0,
172
+ };
173
+ }
174
+ if (typeof resultPtr === 'string') {
175
+ try {
176
+ return JSON.parse(resultPtr);
177
+ }
178
+ catch {
179
+ return {
180
+ success: true,
181
+ bytesSaved: 0,
182
+ originalSize: 0,
183
+ optimizedSize: 0,
184
+ compressionRatio: 0,
185
+ };
186
+ }
187
+ }
188
+ // Handle native result handle
189
+ const bytesSaved = this.native?.pdf_optimization_result_bytes_saved?.(resultPtr) ?? 0;
190
+ return {
191
+ success: true,
192
+ bytesSaved,
193
+ originalSize: 0,
194
+ optimizedSize: 0,
195
+ compressionRatio: 0,
196
+ };
197
+ }
198
+ freeOptimizationResult(resultPtr) {
199
+ if (resultPtr && typeof resultPtr !== 'string' && this.native?.pdf_optimization_result_free) {
200
+ this.native.pdf_optimization_result_free(resultPtr);
201
+ }
202
+ }
203
+ // ===========================================================================
204
+ // Cleanup
205
+ // ===========================================================================
206
+ /**
207
+ * Releases resources held by this manager.
208
+ */
209
+ destroy() {
210
+ this.removeAllListeners();
211
+ }
212
+ }
213
+ export default OptimizationManager;
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Manager for PDF document outlines (bookmarks)
3
+ *
4
+ * Provides functionality for reading and navigating the document's outline tree,
5
+ * which represents the hierarchical bookmark structure.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { OutlineManager } from 'pdf_oxide';
10
+ *
11
+ * const doc = PdfDocument.open('document.pdf');
12
+ * const outlineManager = new OutlineManager(doc);
13
+ *
14
+ * if (outlineManager.hasOutlines()) {
15
+ * const outlines = outlineManager.getOutlines();
16
+ * console.log(`Found ${outlines.length} outline items`);
17
+ * }
18
+ * ```
19
+ */
20
+ export interface OutlineItem {
21
+ title: string;
22
+ pageIndex: number;
23
+ pageNumber: number | null;
24
+ level: number;
25
+ }
26
+ export declare class OutlineManager {
27
+ private _document;
28
+ /**
29
+ * Creates a new OutlineManager for the given document
30
+ * @param document - The PDF document
31
+ * @throws Error if document is null or undefined
32
+ */
33
+ constructor(document: any);
34
+ /**
35
+ * Checks if the document has an outline (bookmarks)
36
+ * @returns True if the document has outlines
37
+ */
38
+ hasOutlines(): boolean;
39
+ /**
40
+ * Gets the number of top-level outline items
41
+ * @returns Number of outline items
42
+ */
43
+ getOutlineCount(): number;
44
+ /**
45
+ * Gets all outline items (flattened)
46
+ * @returns Array of outline items
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const outlines = manager.getOutlines();
51
+ * outlines.forEach(item => {
52
+ * console.log(`${item.title} -> Page ${item.pageNumber}`);
53
+ * });
54
+ * ```
55
+ */
56
+ getOutlines(): OutlineItem[];
57
+ /**
58
+ * Finds an outline item by title (case-insensitive substring match)
59
+ * @param titleFragment - Partial title to search for
60
+ * @returns Matching outline item or null
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const item = manager.findByTitle('Introduction');
65
+ * if (item) {
66
+ * console.log(`Found: ${item.title} on page ${item.pageNumber}`);
67
+ * }
68
+ * ```
69
+ */
70
+ findByTitle(titleFragment: string): OutlineItem | null;
71
+ /**
72
+ * Finds all outline items by title (case-insensitive substring match)
73
+ * @param titleFragment - Partial title to search for
74
+ * @returns Array of matching outline items
75
+ */
76
+ findAllByTitle(titleFragment: string): OutlineItem[];
77
+ /**
78
+ * Gets outline items for a specific page
79
+ * @param pageIndex - Zero-based page index
80
+ * @returns Outline items on that page
81
+ */
82
+ getOutlinesForPage(pageIndex: number): OutlineItem[];
83
+ /**
84
+ * Checks if a specific page has outline items
85
+ * @param pageIndex - Zero-based page index
86
+ * @returns True if page has outline items
87
+ */
88
+ pageHasOutlines(pageIndex: number): boolean;
89
+ /**
90
+ * Gets an outline item by index
91
+ * @param index - Item index
92
+ * @returns Outline item or null if not found
93
+ */
94
+ getOutlineAt(index: number): OutlineItem | null;
95
+ /**
96
+ * Checks if a page number exists in the outline
97
+ * @param pageNumber - One-based page number
98
+ * @returns True if page appears in outline
99
+ */
100
+ containsPageNumber(pageNumber: number): boolean;
101
+ }
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Manager for PDF document outlines (bookmarks)
3
+ *
4
+ * Provides functionality for reading and navigating the document's outline tree,
5
+ * which represents the hierarchical bookmark structure.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { OutlineManager } from 'pdf_oxide';
10
+ *
11
+ * const doc = PdfDocument.open('document.pdf');
12
+ * const outlineManager = new OutlineManager(doc);
13
+ *
14
+ * if (outlineManager.hasOutlines()) {
15
+ * const outlines = outlineManager.getOutlines();
16
+ * console.log(`Found ${outlines.length} outline items`);
17
+ * }
18
+ * ```
19
+ */
20
+ export class OutlineManager {
21
+ /**
22
+ * Creates a new OutlineManager for the given document
23
+ * @param document - The PDF document
24
+ * @throws Error if document is null or undefined
25
+ */
26
+ constructor(document) {
27
+ if (!document) {
28
+ throw new Error('Document is required');
29
+ }
30
+ this._document = document;
31
+ }
32
+ /**
33
+ * Checks if the document has an outline (bookmarks)
34
+ * @returns True if the document has outlines
35
+ */
36
+ hasOutlines() {
37
+ try {
38
+ return this._document.hasOutlines();
39
+ }
40
+ catch (error) {
41
+ return false;
42
+ }
43
+ }
44
+ /**
45
+ * Gets the number of top-level outline items
46
+ * @returns Number of outline items
47
+ */
48
+ getOutlineCount() {
49
+ try {
50
+ return this._document.getOutlineCount();
51
+ }
52
+ catch (error) {
53
+ return 0;
54
+ }
55
+ }
56
+ /**
57
+ * Gets all outline items (flattened)
58
+ * @returns Array of outline items
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const outlines = manager.getOutlines();
63
+ * outlines.forEach(item => {
64
+ * console.log(`${item.title} -> Page ${item.pageNumber}`);
65
+ * });
66
+ * ```
67
+ */
68
+ getOutlines() {
69
+ try {
70
+ const rawOutlines = this._document.getOutlines();
71
+ // Convert native OutlineInfo to OutlineItem format expected by JS
72
+ return rawOutlines.map((item) => ({
73
+ title: item.title,
74
+ pageIndex: item.pageIndex,
75
+ pageNumber: item.pageIndex >= 0 ? item.pageIndex + 1 : null,
76
+ level: item.level,
77
+ }));
78
+ }
79
+ catch (error) {
80
+ return [];
81
+ }
82
+ }
83
+ /**
84
+ * Finds an outline item by title (case-insensitive substring match)
85
+ * @param titleFragment - Partial title to search for
86
+ * @returns Matching outline item or null
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * const item = manager.findByTitle('Introduction');
91
+ * if (item) {
92
+ * console.log(`Found: ${item.title} on page ${item.pageNumber}`);
93
+ * }
94
+ * ```
95
+ */
96
+ findByTitle(titleFragment) {
97
+ if (!titleFragment || typeof titleFragment !== 'string') {
98
+ throw new Error('Title fragment must be a non-empty string');
99
+ }
100
+ const outlines = this.getOutlines();
101
+ const fragment = titleFragment.toLowerCase();
102
+ for (const item of outlines) {
103
+ if (item.title && item.title.toLowerCase().includes(fragment)) {
104
+ return item;
105
+ }
106
+ }
107
+ return null;
108
+ }
109
+ /**
110
+ * Finds all outline items by title (case-insensitive substring match)
111
+ * @param titleFragment - Partial title to search for
112
+ * @returns Array of matching outline items
113
+ */
114
+ findAllByTitle(titleFragment) {
115
+ if (!titleFragment || typeof titleFragment !== 'string') {
116
+ throw new Error('Title fragment must be a non-empty string');
117
+ }
118
+ const outlines = this.getOutlines();
119
+ const fragment = titleFragment.toLowerCase();
120
+ return outlines.filter((item) => item.title && item.title.toLowerCase().includes(fragment));
121
+ }
122
+ /**
123
+ * Gets outline items for a specific page
124
+ * @param pageIndex - Zero-based page index
125
+ * @returns Outline items on that page
126
+ */
127
+ getOutlinesForPage(pageIndex) {
128
+ if (typeof pageIndex !== 'number' || pageIndex < 0) {
129
+ throw new Error('Page index must be a non-negative number');
130
+ }
131
+ const outlines = this.getOutlines();
132
+ return outlines.filter((item) => item.pageIndex === pageIndex);
133
+ }
134
+ /**
135
+ * Checks if a specific page has outline items
136
+ * @param pageIndex - Zero-based page index
137
+ * @returns True if page has outline items
138
+ */
139
+ pageHasOutlines(pageIndex) {
140
+ if (typeof pageIndex !== 'number' || pageIndex < 0) {
141
+ throw new Error('Page index must be a non-negative number');
142
+ }
143
+ return this.getOutlinesForPage(pageIndex).length > 0;
144
+ }
145
+ /**
146
+ * Gets an outline item by index
147
+ * @param index - Item index
148
+ * @returns Outline item or null if not found
149
+ */
150
+ getOutlineAt(index) {
151
+ if (typeof index !== 'number' || index < 0) {
152
+ throw new Error('Index must be a non-negative number');
153
+ }
154
+ const outlines = this.getOutlines();
155
+ return outlines[index] || null;
156
+ }
157
+ /**
158
+ * Checks if a page number exists in the outline
159
+ * @param pageNumber - One-based page number
160
+ * @returns True if page appears in outline
161
+ */
162
+ containsPageNumber(pageNumber) {
163
+ if (typeof pageNumber !== 'number' || pageNumber < 1) {
164
+ throw new Error('Page number must be a positive number');
165
+ }
166
+ const outlines = this.getOutlines();
167
+ return outlines.some((item) => item.pageNumber === pageNumber);
168
+ }
169
+ }
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Manager for PDF page-level operations
3
+ *
4
+ * Provides methods to query page count, dimensions, and validate indices.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { PageManager } from 'pdf_oxide';
9
+ *
10
+ * const doc = PdfDocument.open('document.pdf');
11
+ * const pageManager = new PageManager(doc);
12
+ *
13
+ * console.log(`Document has ${pageManager.getPageCount()} pages`);
14
+ *
15
+ * if (pageManager.isValidPageIndex(5)) {
16
+ * const info = pageManager.getPageInfo(5);
17
+ * console.log(`Page 5: ${info.width} x ${info.height} points`);
18
+ * }
19
+ * ```
20
+ */
21
+ export interface PageInfo {
22
+ index: number;
23
+ width: number;
24
+ height: number;
25
+ }
26
+ export interface PageRange {
27
+ firstPage: number;
28
+ lastPage: number;
29
+ }
30
+ export interface PageStatistics {
31
+ count: number;
32
+ minWidth: number;
33
+ maxWidth: number;
34
+ minHeight: number;
35
+ maxHeight: number;
36
+ averageWidth: number;
37
+ averageHeight: number;
38
+ hasVariableSizes: boolean;
39
+ }
40
+ export declare class PageManager {
41
+ private _document;
42
+ private _cache;
43
+ /**
44
+ * Creates a new PageManager for the given document
45
+ * @param document - The PDF document
46
+ * @throws Error if document is null or undefined
47
+ */
48
+ constructor(document: any);
49
+ /**
50
+ * Clears the page cache
51
+ */
52
+ clearCache(): void;
53
+ /**
54
+ * Gets the total number of pages in the document
55
+ * @returns Number of pages
56
+ */
57
+ getPageCount(): number;
58
+ /**
59
+ * Checks if a page index is valid for this document
60
+ * @param pageIndex - Page index to validate (0-based)
61
+ * @returns True if the page index is valid
62
+ */
63
+ isValidPageIndex(pageIndex: number): boolean;
64
+ /**
65
+ * Gets information about a specific page
66
+ * @param pageIndex - Page index (0-based)
67
+ * @returns PageInfo object with page dimensions
68
+ * @throws Error if page index is invalid
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * const info = manager.getPageInfo(0);
73
+ * console.log(`Page 0: ${info.width} x ${info.height} points`);
74
+ * ```
75
+ */
76
+ getPageInfo(pageIndex: number): PageInfo;
77
+ /**
78
+ * Gets information about all pages in the document
79
+ * @returns Array of PageInfo objects
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * const pages = manager.getAllPageInfo();
84
+ * pages.forEach(page => {
85
+ * console.log(`Page ${page.index}: ${page.width} x ${page.height}`);
86
+ * });
87
+ * ```
88
+ */
89
+ getAllPageInfo(): PageInfo[];
90
+ /**
91
+ * Checks if the document has no pages
92
+ * @returns True if the document has no pages
93
+ */
94
+ isEmpty(): boolean;
95
+ /**
96
+ * Checks if the document has more than one page
97
+ * @returns True if document has multiple pages
98
+ */
99
+ hasMultiplePages(): boolean;
100
+ /**
101
+ * Gets the valid page range
102
+ * @returns Object with firstPage and lastPage indices
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * const range = manager.getPageRange();
107
+ * console.log(`Page range: ${range.firstPage} to ${range.lastPage}`);
108
+ * ```
109
+ */
110
+ getPageRange(): PageRange;
111
+ /**
112
+ * Gets page dimension statistics
113
+ * @returns Statistics about page dimensions
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * const stats = manager.getPageStatistics();
118
+ * console.log(`Average width: ${stats.averageWidth}`);
119
+ * console.log(`Pages vary in size: ${stats.hasVariableSizes}`);
120
+ * ```
121
+ */
122
+ getPageStatistics(): PageStatistics;
123
+ /**
124
+ * Gets pages within a specific size range
125
+ * @param minWidth - Minimum width
126
+ * @param maxWidth - Maximum width
127
+ * @param minHeight - Minimum height
128
+ * @param maxHeight - Maximum height
129
+ * @returns Matching PageInfo objects
130
+ */
131
+ getPagesInSizeRange(minWidth: number, maxWidth: number, minHeight: number, maxHeight: number): PageInfo[];
132
+ /**
133
+ * Gets landscape pages
134
+ * @returns Array of landscape PageInfo objects
135
+ */
136
+ getLandscapePages(): PageInfo[];
137
+ /**
138
+ * Gets portrait pages
139
+ * @returns Array of portrait PageInfo objects
140
+ */
141
+ getPortraitPages(): PageInfo[];
142
+ }