pdf-codec 5.3.32 → 5.5.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/README.md +21 -1
- package/dist/annotations.d.cts +1 -1
- package/dist/annotations.d.ts +1 -1
- package/dist/attachments.d.cts +1 -1
- package/dist/attachments.d.ts +1 -1
- package/dist/cmap.d.cts +1 -1
- package/dist/cmap.d.ts +1 -1
- package/dist/codec.d.cts +10 -0
- package/dist/codec.d.ts +10 -0
- package/dist/content-read.d.cts +1 -1
- package/dist/content-read.d.ts +1 -1
- package/dist/diagnostics-BkG_Ej2x.d.cts +32 -0
- package/dist/diagnostics-BkG_Ej2x.d.ts +32 -0
- package/dist/diagnostics.cjs +17 -0
- package/dist/diagnostics.d.cts +2 -2
- package/dist/diagnostics.d.ts +2 -2
- package/dist/diagnostics.js +17 -1
- package/dist/document.d.cts +1 -1
- package/dist/document.d.ts +1 -1
- package/dist/encrypt.d.cts +1 -1
- package/dist/encrypt.d.ts +1 -1
- package/dist/filters.d.cts +1 -1
- package/dist/filters.d.ts +1 -1
- package/dist/font-read.d.cts +1 -1
- package/dist/font-read.d.ts +1 -1
- package/dist/form.d.cts +1 -1
- package/dist/form.d.ts +1 -1
- package/dist/images-read.d.cts +1 -1
- package/dist/images-read.d.ts +1 -1
- package/dist/index.cjs +6 -0
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +5 -4
- package/dist/interpret-types.d.cts +1 -1
- package/dist/interpret-types.d.ts +1 -1
- package/dist/layout.cjs +27 -2
- package/dist/layout.d.cts +31 -1
- package/dist/layout.d.ts +31 -1
- package/dist/layout.js +26 -3
- package/dist/names.d.cts +1 -1
- package/dist/names.d.ts +1 -1
- package/dist/navigation.d.cts +1 -1
- package/dist/navigation.d.ts +1 -1
- package/dist/optional-content.d.cts +1 -1
- package/dist/optional-content.d.ts +1 -1
- package/dist/parse.d.cts +1 -1
- package/dist/parse.d.ts +1 -1
- package/dist/predictors.d.cts +1 -1
- package/dist/predictors.d.ts +1 -1
- package/dist/raster-text.d.cts +1 -1
- package/dist/raster-text.d.ts +1 -1
- package/dist/raster.d.cts +1 -1
- package/dist/raster.d.ts +1 -1
- package/dist/read-convert.d.cts +1 -1
- package/dist/read-convert.d.ts +1 -1
- package/dist/read.cjs +44 -17
- package/dist/read.d.cts +32 -3
- package/dist/read.d.ts +32 -3
- package/dist/read.js +45 -18
- package/dist/structure.cjs +13 -3
- package/dist/structure.d.cts +11 -2
- package/dist/structure.d.ts +11 -2
- package/dist/structure.js +13 -3
- package/dist/write-skipped-surfaces.cjs +16 -0
- package/dist/write-skipped-surfaces.d.cts +12 -0
- package/dist/write-skipped-surfaces.d.ts +12 -0
- package/dist/write-skipped-surfaces.js +15 -0
- package/dist/write.cjs +17 -0
- package/dist/write.d.cts +9 -1
- package/dist/write.d.ts +9 -1
- package/dist/write.js +17 -1
- package/dist/xref.d.cts +1 -1
- package/dist/xref.d.ts +1 -1
- package/package.json +1 -1
- package/dist/diagnostics-C9FxfZ6H.d.cts +0 -22
- package/dist/diagnostics-C9FxfZ6H.d.ts +0 -22
package/dist/layout.cjs
CHANGED
|
@@ -173,8 +173,18 @@ const LayoutPageSchema = zod.z.object({
|
|
|
173
173
|
heightPt: zod.z.number().positive(),
|
|
174
174
|
items: zod.z.array(LayoutItemSchema),
|
|
175
175
|
annotations: zod.z.array(LayoutAnnotationSchema).optional(),
|
|
176
|
-
notes: zod.z.string().optional()
|
|
176
|
+
notes: zod.z.string().optional(),
|
|
177
|
+
index: zod.z.number().int().nonnegative().optional()
|
|
177
178
|
});
|
|
179
|
+
/**
|
|
180
|
+
* The zero-based index in the source PDF's page tree of the page at `position` in a `LayoutDocument`'s `pages`: the page's own `index` when a page-selected read set one, otherwise `position` itself, which is the source index whenever `pages` holds every page in document order. The one place that rule is spelled, so every consumer resolving a page against a document-level reference (a destination, a form widget, a frame) agrees on it.
|
|
181
|
+
* @param page - the page as it appears in `pages`
|
|
182
|
+
* @param position - the page's position in `pages`
|
|
183
|
+
* @returns the page's index in the source document's page tree
|
|
184
|
+
*/
|
|
185
|
+
function sourcePageIndex(page, position) {
|
|
186
|
+
return page.index ?? position;
|
|
187
|
+
}
|
|
178
188
|
const LayoutImageAssetSchema = zod.z.object({
|
|
179
189
|
format: zod.z.enum(["png", "jpeg"]),
|
|
180
190
|
base64: zod.z.string(),
|
|
@@ -259,10 +269,22 @@ const LayoutStructureElementSchema = zod.z.lazy(() => zod.z.object({
|
|
|
259
269
|
actualText: zod.z.string().optional(),
|
|
260
270
|
children: zod.z.array(LayoutStructureElementSchema)
|
|
261
271
|
}));
|
|
272
|
+
/**
|
|
273
|
+
* The document-level surfaces a read can leave out (`ReadPdfOptions.surfaces`), each named by the `LayoutDocument` field it fills: `outline`, `destinations`, `form`, `layers` and `structure` are those fields, and `residue` is the package-level `source` channel. A `LayoutDocument` lists the ones its read skipped in `skippedSurfaces`.
|
|
274
|
+
*/
|
|
275
|
+
const LayoutDocumentSurfaceSchema = zod.z.enum([
|
|
276
|
+
"outline",
|
|
277
|
+
"destinations",
|
|
278
|
+
"form",
|
|
279
|
+
"layers",
|
|
280
|
+
"structure",
|
|
281
|
+
"residue"
|
|
282
|
+
]);
|
|
262
283
|
const LayoutDocumentSchema = zod.z.object({
|
|
263
284
|
formatVersion: zod.z.literal(1),
|
|
264
285
|
metadata: document_schema_js.LayoutMetadataSchema,
|
|
265
286
|
pages: zod.z.array(LayoutPageSchema),
|
|
287
|
+
pageCount: zod.z.number().int().nonnegative().optional(),
|
|
266
288
|
images: zod.z.record(zod.z.string(), LayoutImageAssetSchema),
|
|
267
289
|
destinations: zod.z.array(LayoutDestinationSchema).optional(),
|
|
268
290
|
outline: zod.z.array(LayoutOutlineItemSchema).optional(),
|
|
@@ -270,7 +292,8 @@ const LayoutDocumentSchema = zod.z.object({
|
|
|
270
292
|
layers: zod.z.array(LayoutLayerSchema).optional(),
|
|
271
293
|
structure: zod.z.array(LayoutStructureElementSchema).optional(),
|
|
272
294
|
form: zod.z.array(LayoutFormFieldSchema).optional(),
|
|
273
|
-
source: zod.z.record(zod.z.string(), document_schema_js.SourceResidueSchema).optional()
|
|
295
|
+
source: zod.z.record(zod.z.string(), document_schema_js.SourceResidueSchema).optional(),
|
|
296
|
+
skippedSurfaces: zod.z.array(LayoutDocumentSurfaceSchema).min(1).optional()
|
|
274
297
|
});
|
|
275
298
|
//#endregion
|
|
276
299
|
exports.LAYOUT_FORMAT_VERSION = LAYOUT_FORMAT_VERSION;
|
|
@@ -280,6 +303,7 @@ exports.LayoutAttachmentSchema = LayoutAttachmentSchema;
|
|
|
280
303
|
exports.LayoutDestinationSchema = LayoutDestinationSchema;
|
|
281
304
|
exports.LayoutDestinationTargetSchema = LayoutDestinationTargetSchema;
|
|
282
305
|
exports.LayoutDocumentSchema = LayoutDocumentSchema;
|
|
306
|
+
exports.LayoutDocumentSurfaceSchema = LayoutDocumentSurfaceSchema;
|
|
283
307
|
exports.LayoutEllipseSchema = LayoutEllipseSchema;
|
|
284
308
|
exports.LayoutFormFieldSchema = LayoutFormFieldSchema;
|
|
285
309
|
exports.LayoutFormWidgetSchema = LayoutFormWidgetSchema;
|
|
@@ -298,3 +322,4 @@ exports.LayoutRectSchema = LayoutRectSchema;
|
|
|
298
322
|
exports.LayoutStructureElementSchema = LayoutStructureElementSchema;
|
|
299
323
|
exports.LayoutSubpathSchema = LayoutSubpathSchema;
|
|
300
324
|
exports.LayoutTextSchema = LayoutTextSchema;
|
|
325
|
+
exports.sourcePageIndex = sourcePageIndex;
|
package/dist/layout.d.cts
CHANGED
|
@@ -668,8 +668,16 @@ declare const LayoutPageSchema: z.ZodObject<{
|
|
|
668
668
|
}, z.core.$strict>>;
|
|
669
669
|
}, z.core.$strip>>>;
|
|
670
670
|
notes: z.ZodOptional<z.ZodString>;
|
|
671
|
+
index: z.ZodOptional<z.ZodNumber>;
|
|
671
672
|
}, z.core.$strip>;
|
|
672
673
|
type LayoutPage = z.infer<typeof LayoutPageSchema>;
|
|
674
|
+
/**
|
|
675
|
+
* The zero-based index in the source PDF's page tree of the page at `position` in a `LayoutDocument`'s `pages`: the page's own `index` when a page-selected read set one, otherwise `position` itself, which is the source index whenever `pages` holds every page in document order. The one place that rule is spelled, so every consumer resolving a page against a document-level reference (a destination, a form widget, a frame) agrees on it.
|
|
676
|
+
* @param page - the page as it appears in `pages`
|
|
677
|
+
* @param position - the page's position in `pages`
|
|
678
|
+
* @returns the page's index in the source document's page tree
|
|
679
|
+
*/
|
|
680
|
+
declare function sourcePageIndex(page: LayoutPage, position: number): number;
|
|
673
681
|
declare const LayoutImageAssetSchema: z.ZodObject<{
|
|
674
682
|
format: z.ZodEnum<{
|
|
675
683
|
png: "png";
|
|
@@ -776,6 +784,18 @@ interface LayoutStructureElement {
|
|
|
776
784
|
readonly actualText?: string;
|
|
777
785
|
readonly children: readonly LayoutStructureElement[];
|
|
778
786
|
}
|
|
787
|
+
/**
|
|
788
|
+
* The document-level surfaces a read can leave out (`ReadPdfOptions.surfaces`), each named by the `LayoutDocument` field it fills: `outline`, `destinations`, `form`, `layers` and `structure` are those fields, and `residue` is the package-level `source` channel. A `LayoutDocument` lists the ones its read skipped in `skippedSurfaces`.
|
|
789
|
+
*/
|
|
790
|
+
declare const LayoutDocumentSurfaceSchema: z.ZodEnum<{
|
|
791
|
+
structure: "structure";
|
|
792
|
+
destinations: "destinations";
|
|
793
|
+
outline: "outline";
|
|
794
|
+
layers: "layers";
|
|
795
|
+
form: "form";
|
|
796
|
+
residue: "residue";
|
|
797
|
+
}>;
|
|
798
|
+
type LayoutDocumentSurface = z.infer<typeof LayoutDocumentSurfaceSchema>;
|
|
779
799
|
declare const LayoutDocumentSchema: z.ZodObject<{
|
|
780
800
|
formatVersion: z.ZodLiteral<1>;
|
|
781
801
|
metadata: z.ZodObject<{
|
|
@@ -1019,7 +1039,9 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
1019
1039
|
}, z.core.$strict>>;
|
|
1020
1040
|
}, z.core.$strip>>>;
|
|
1021
1041
|
notes: z.ZodOptional<z.ZodString>;
|
|
1042
|
+
index: z.ZodOptional<z.ZodNumber>;
|
|
1022
1043
|
}, z.core.$strip>>;
|
|
1044
|
+
pageCount: z.ZodOptional<z.ZodNumber>;
|
|
1023
1045
|
images: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
1024
1046
|
format: z.ZodEnum<{
|
|
1025
1047
|
png: "png";
|
|
@@ -1091,7 +1113,15 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
1091
1113
|
}>;
|
|
1092
1114
|
xml: z.ZodString;
|
|
1093
1115
|
}, z.core.$strict>>>;
|
|
1116
|
+
skippedSurfaces: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
1117
|
+
structure: "structure";
|
|
1118
|
+
destinations: "destinations";
|
|
1119
|
+
outline: "outline";
|
|
1120
|
+
layers: "layers";
|
|
1121
|
+
form: "form";
|
|
1122
|
+
residue: "residue";
|
|
1123
|
+
}>>>;
|
|
1094
1124
|
}, z.core.$strip>;
|
|
1095
1125
|
type LayoutDocument = z.infer<typeof LayoutDocumentSchema>;
|
|
1096
1126
|
//#endregion
|
|
1097
|
-
export { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutStructureElement, LayoutStructureElementSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema };
|
|
1127
|
+
export { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutDocumentSurface, LayoutDocumentSurfaceSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutStructureElement, LayoutStructureElementSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema, sourcePageIndex };
|
package/dist/layout.d.ts
CHANGED
|
@@ -668,8 +668,16 @@ declare const LayoutPageSchema: z.ZodObject<{
|
|
|
668
668
|
}, z.core.$strict>>;
|
|
669
669
|
}, z.core.$strip>>>;
|
|
670
670
|
notes: z.ZodOptional<z.ZodString>;
|
|
671
|
+
index: z.ZodOptional<z.ZodNumber>;
|
|
671
672
|
}, z.core.$strip>;
|
|
672
673
|
type LayoutPage = z.infer<typeof LayoutPageSchema>;
|
|
674
|
+
/**
|
|
675
|
+
* The zero-based index in the source PDF's page tree of the page at `position` in a `LayoutDocument`'s `pages`: the page's own `index` when a page-selected read set one, otherwise `position` itself, which is the source index whenever `pages` holds every page in document order. The one place that rule is spelled, so every consumer resolving a page against a document-level reference (a destination, a form widget, a frame) agrees on it.
|
|
676
|
+
* @param page - the page as it appears in `pages`
|
|
677
|
+
* @param position - the page's position in `pages`
|
|
678
|
+
* @returns the page's index in the source document's page tree
|
|
679
|
+
*/
|
|
680
|
+
declare function sourcePageIndex(page: LayoutPage, position: number): number;
|
|
673
681
|
declare const LayoutImageAssetSchema: z.ZodObject<{
|
|
674
682
|
format: z.ZodEnum<{
|
|
675
683
|
png: "png";
|
|
@@ -776,6 +784,18 @@ interface LayoutStructureElement {
|
|
|
776
784
|
readonly actualText?: string;
|
|
777
785
|
readonly children: readonly LayoutStructureElement[];
|
|
778
786
|
}
|
|
787
|
+
/**
|
|
788
|
+
* The document-level surfaces a read can leave out (`ReadPdfOptions.surfaces`), each named by the `LayoutDocument` field it fills: `outline`, `destinations`, `form`, `layers` and `structure` are those fields, and `residue` is the package-level `source` channel. A `LayoutDocument` lists the ones its read skipped in `skippedSurfaces`.
|
|
789
|
+
*/
|
|
790
|
+
declare const LayoutDocumentSurfaceSchema: z.ZodEnum<{
|
|
791
|
+
structure: "structure";
|
|
792
|
+
destinations: "destinations";
|
|
793
|
+
outline: "outline";
|
|
794
|
+
layers: "layers";
|
|
795
|
+
form: "form";
|
|
796
|
+
residue: "residue";
|
|
797
|
+
}>;
|
|
798
|
+
type LayoutDocumentSurface = z.infer<typeof LayoutDocumentSurfaceSchema>;
|
|
779
799
|
declare const LayoutDocumentSchema: z.ZodObject<{
|
|
780
800
|
formatVersion: z.ZodLiteral<1>;
|
|
781
801
|
metadata: z.ZodObject<{
|
|
@@ -1019,7 +1039,9 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
1019
1039
|
}, z.core.$strict>>;
|
|
1020
1040
|
}, z.core.$strip>>>;
|
|
1021
1041
|
notes: z.ZodOptional<z.ZodString>;
|
|
1042
|
+
index: z.ZodOptional<z.ZodNumber>;
|
|
1022
1043
|
}, z.core.$strip>>;
|
|
1044
|
+
pageCount: z.ZodOptional<z.ZodNumber>;
|
|
1023
1045
|
images: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
1024
1046
|
format: z.ZodEnum<{
|
|
1025
1047
|
png: "png";
|
|
@@ -1091,7 +1113,15 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
1091
1113
|
}>;
|
|
1092
1114
|
xml: z.ZodString;
|
|
1093
1115
|
}, z.core.$strict>>>;
|
|
1116
|
+
skippedSurfaces: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
1117
|
+
structure: "structure";
|
|
1118
|
+
destinations: "destinations";
|
|
1119
|
+
outline: "outline";
|
|
1120
|
+
layers: "layers";
|
|
1121
|
+
form: "form";
|
|
1122
|
+
residue: "residue";
|
|
1123
|
+
}>>>;
|
|
1094
1124
|
}, z.core.$strip>;
|
|
1095
1125
|
type LayoutDocument = z.infer<typeof LayoutDocumentSchema>;
|
|
1096
1126
|
//#endregion
|
|
1097
|
-
export { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutStructureElement, LayoutStructureElementSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema };
|
|
1127
|
+
export { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutDocumentSurface, LayoutDocumentSurfaceSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutStructureElement, LayoutStructureElementSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema, sourcePageIndex };
|
package/dist/layout.js
CHANGED
|
@@ -172,8 +172,18 @@ const LayoutPageSchema = z.object({
|
|
|
172
172
|
heightPt: z.number().positive(),
|
|
173
173
|
items: z.array(LayoutItemSchema),
|
|
174
174
|
annotations: z.array(LayoutAnnotationSchema).optional(),
|
|
175
|
-
notes: z.string().optional()
|
|
175
|
+
notes: z.string().optional(),
|
|
176
|
+
index: z.number().int().nonnegative().optional()
|
|
176
177
|
});
|
|
178
|
+
/**
|
|
179
|
+
* The zero-based index in the source PDF's page tree of the page at `position` in a `LayoutDocument`'s `pages`: the page's own `index` when a page-selected read set one, otherwise `position` itself, which is the source index whenever `pages` holds every page in document order. The one place that rule is spelled, so every consumer resolving a page against a document-level reference (a destination, a form widget, a frame) agrees on it.
|
|
180
|
+
* @param page - the page as it appears in `pages`
|
|
181
|
+
* @param position - the page's position in `pages`
|
|
182
|
+
* @returns the page's index in the source document's page tree
|
|
183
|
+
*/
|
|
184
|
+
function sourcePageIndex(page, position) {
|
|
185
|
+
return page.index ?? position;
|
|
186
|
+
}
|
|
177
187
|
const LayoutImageAssetSchema = z.object({
|
|
178
188
|
format: z.enum(["png", "jpeg"]),
|
|
179
189
|
base64: z.string(),
|
|
@@ -258,10 +268,22 @@ const LayoutStructureElementSchema = z.lazy(() => z.object({
|
|
|
258
268
|
actualText: z.string().optional(),
|
|
259
269
|
children: z.array(LayoutStructureElementSchema)
|
|
260
270
|
}));
|
|
271
|
+
/**
|
|
272
|
+
* The document-level surfaces a read can leave out (`ReadPdfOptions.surfaces`), each named by the `LayoutDocument` field it fills: `outline`, `destinations`, `form`, `layers` and `structure` are those fields, and `residue` is the package-level `source` channel. A `LayoutDocument` lists the ones its read skipped in `skippedSurfaces`.
|
|
273
|
+
*/
|
|
274
|
+
const LayoutDocumentSurfaceSchema = z.enum([
|
|
275
|
+
"outline",
|
|
276
|
+
"destinations",
|
|
277
|
+
"form",
|
|
278
|
+
"layers",
|
|
279
|
+
"structure",
|
|
280
|
+
"residue"
|
|
281
|
+
]);
|
|
261
282
|
const LayoutDocumentSchema = z.object({
|
|
262
283
|
formatVersion: z.literal(1),
|
|
263
284
|
metadata: LayoutMetadataSchema,
|
|
264
285
|
pages: z.array(LayoutPageSchema),
|
|
286
|
+
pageCount: z.number().int().nonnegative().optional(),
|
|
265
287
|
images: z.record(z.string(), LayoutImageAssetSchema),
|
|
266
288
|
destinations: z.array(LayoutDestinationSchema).optional(),
|
|
267
289
|
outline: z.array(LayoutOutlineItemSchema).optional(),
|
|
@@ -269,7 +291,8 @@ const LayoutDocumentSchema = z.object({
|
|
|
269
291
|
layers: z.array(LayoutLayerSchema).optional(),
|
|
270
292
|
structure: z.array(LayoutStructureElementSchema).optional(),
|
|
271
293
|
form: z.array(LayoutFormFieldSchema).optional(),
|
|
272
|
-
source: z.record(z.string(), SourceResidueSchema).optional()
|
|
294
|
+
source: z.record(z.string(), SourceResidueSchema).optional(),
|
|
295
|
+
skippedSurfaces: z.array(LayoutDocumentSurfaceSchema).min(1).optional()
|
|
273
296
|
});
|
|
274
297
|
//#endregion
|
|
275
|
-
export { LAYOUT_FORMAT_VERSION, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachmentSchema, LayoutDestinationSchema, LayoutDestinationTargetSchema, LayoutDocumentSchema, LayoutEllipseSchema, LayoutFormFieldSchema, LayoutFormWidgetSchema, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLinkSchema, LayoutItemSchema, LayoutLayerSchema, LayoutLineSchema, LayoutLinkSchema, LayoutOutlineItemSchema, LayoutPageSchema, LayoutPathSchema, LayoutPathSegmentSchema, LayoutRectSchema, LayoutStructureElementSchema, LayoutSubpathSchema, LayoutTextSchema };
|
|
298
|
+
export { LAYOUT_FORMAT_VERSION, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachmentSchema, LayoutDestinationSchema, LayoutDestinationTargetSchema, LayoutDocumentSchema, LayoutDocumentSurfaceSchema, LayoutEllipseSchema, LayoutFormFieldSchema, LayoutFormWidgetSchema, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLinkSchema, LayoutItemSchema, LayoutLayerSchema, LayoutLineSchema, LayoutLinkSchema, LayoutOutlineItemSchema, LayoutPageSchema, LayoutPathSchema, LayoutPathSegmentSchema, LayoutRectSchema, LayoutStructureElementSchema, LayoutSubpathSchema, LayoutTextSchema, sourcePageIndex };
|
package/dist/names.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PdfDiagnosticSink } from "./diagnostics-
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-BkG_Ej2x.cjs";
|
|
2
2
|
import { r as PdfObject } from "./objects-e2RS3-yT.cjs";
|
|
3
3
|
import { PdfObjectResolver } from "./interpret-types.cjs";
|
|
4
4
|
//#region src/names.d.ts
|
package/dist/names.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PdfDiagnosticSink } from "./diagnostics-
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-BkG_Ej2x.js";
|
|
2
2
|
import { r as PdfObject } from "./objects-e2RS3-yT.js";
|
|
3
3
|
import { PdfObjectResolver } from "./interpret-types.js";
|
|
4
4
|
//#region src/names.d.ts
|
package/dist/navigation.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PdfDiagnosticSink } from "./diagnostics-
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-BkG_Ej2x.cjs";
|
|
2
2
|
import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.cjs";
|
|
3
3
|
import { PdfObjectResolver } from "./interpret-types.cjs";
|
|
4
4
|
import { LayoutDestination, LayoutDestinationTarget, LayoutOutlineItem } from "./layout.cjs";
|
package/dist/navigation.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PdfDiagnosticSink } from "./diagnostics-
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-BkG_Ej2x.js";
|
|
2
2
|
import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.js";
|
|
3
3
|
import { PdfObjectResolver } from "./interpret-types.js";
|
|
4
4
|
import { LayoutDestination, LayoutDestinationTarget, LayoutOutlineItem } from "./layout.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PdfDiagnosticSink } from "./diagnostics-
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-BkG_Ej2x.cjs";
|
|
2
2
|
import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.cjs";
|
|
3
3
|
import { PdfObjectResolver } from "./interpret-types.cjs";
|
|
4
4
|
import { LayoutLayer } from "./layout.cjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PdfDiagnosticSink } from "./diagnostics-
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-BkG_Ej2x.js";
|
|
2
2
|
import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.js";
|
|
3
3
|
import { PdfObjectResolver } from "./interpret-types.js";
|
|
4
4
|
import { LayoutLayer } from "./layout.js";
|
package/dist/parse.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PdfDiagnosticSink } from "./diagnostics-
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-BkG_Ej2x.cjs";
|
|
2
2
|
import { r as PdfObject } from "./objects-e2RS3-yT.cjs";
|
|
3
3
|
import { ByteReader } from "./bytes/reader.cjs";
|
|
4
4
|
//#region src/parse.d.ts
|
package/dist/parse.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PdfDiagnosticSink } from "./diagnostics-
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-BkG_Ej2x.js";
|
|
2
2
|
import { r as PdfObject } from "./objects-e2RS3-yT.js";
|
|
3
3
|
import { ByteReader } from "./bytes/reader.js";
|
|
4
4
|
//#region src/parse.d.ts
|
package/dist/predictors.d.cts
CHANGED
package/dist/predictors.d.ts
CHANGED
package/dist/raster-text.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PdfDiagnosticSink } from "./diagnostics-
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-BkG_Ej2x.cjs";
|
|
2
2
|
import { n as PdfDict } from "./objects-e2RS3-yT.cjs";
|
|
3
3
|
import { r as Matrix } from "./matrix-B7_SBKQ5.cjs";
|
|
4
4
|
import { ExtractedTextRun, PdfObjectResolver } from "./interpret-types.cjs";
|
package/dist/raster-text.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PdfDiagnosticSink } from "./diagnostics-
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-BkG_Ej2x.js";
|
|
2
2
|
import { n as PdfDict } from "./objects-e2RS3-yT.js";
|
|
3
3
|
import { r as Matrix } from "./matrix-B7_SBKQ5.js";
|
|
4
4
|
import { ExtractedTextRun, PdfObjectResolver } from "./interpret-types.js";
|
package/dist/raster.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PdfDiagnosticSink } from "./diagnostics-
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-BkG_Ej2x.cjs";
|
|
2
2
|
import { t as SfntFont } from "./sfnt-V08bb5ut.cjs";
|
|
3
3
|
import { r as GlyfTable } from "./glyf-DFyknMrW.cjs";
|
|
4
4
|
import { Color } from "document-schema.js";
|
package/dist/raster.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PdfDiagnosticSink } from "./diagnostics-
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-BkG_Ej2x.js";
|
|
2
2
|
import { t as SfntFont } from "./sfnt-V08bb5ut.js";
|
|
3
3
|
import { r as GlyfTable } from "./glyf-Bv1katwK.js";
|
|
4
4
|
import { Color } from "document-schema.js";
|
package/dist/read-convert.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PdfDiagnosticSink } from "./diagnostics-
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-BkG_Ej2x.cjs";
|
|
2
2
|
import { n as PdfDict } from "./objects-e2RS3-yT.cjs";
|
|
3
3
|
import { r as Matrix } from "./matrix-B7_SBKQ5.cjs";
|
|
4
4
|
import { ExtractedEllipse, ExtractedImage, ExtractedItem, ExtractedLine, ExtractedPaint, ExtractedPath, ExtractedRect, ExtractedSubpath, ExtractedTextRun, PdfObjectResolver } from "./interpret-types.cjs";
|
package/dist/read-convert.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PdfDiagnosticSink } from "./diagnostics-
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-BkG_Ej2x.js";
|
|
2
2
|
import { n as PdfDict } from "./objects-e2RS3-yT.js";
|
|
3
3
|
import { r as Matrix } from "./matrix-B7_SBKQ5.js";
|
|
4
4
|
import { ExtractedEllipse, ExtractedImage, ExtractedItem, ExtractedLine, ExtractedPaint, ExtractedPath, ExtractedRect, ExtractedSubpath, ExtractedTextRun, PdfObjectResolver } from "./interpret-types.js";
|
package/dist/read.cjs
CHANGED
|
@@ -12,7 +12,7 @@ const require_form = require("./form.cjs");
|
|
|
12
12
|
const require_xmp = require("./xmp.cjs");
|
|
13
13
|
const require_optional_content = require("./optional-content.cjs");
|
|
14
14
|
const require_structure = require("./structure.cjs");
|
|
15
|
-
require("./layout.cjs");
|
|
15
|
+
const require_layout = require("./layout.cjs");
|
|
16
16
|
const require_diagnostics = require("./diagnostics.cjs");
|
|
17
17
|
const require_document = require("./document.cjs");
|
|
18
18
|
const require_util_abort = require("./util/abort.cjs");
|
|
@@ -20,6 +20,22 @@ const require_font_read = require("./font-read.cjs");
|
|
|
20
20
|
const require_interpret = require("./interpret-BDVrFWhd.cjs");
|
|
21
21
|
const require_navigation = require("./navigation.cjs");
|
|
22
22
|
//#region src/read.ts
|
|
23
|
+
function skippedSurfacesOf(surfaces) {
|
|
24
|
+
return require_layout.LayoutDocumentSurfaceSchema.options.filter((surface) => surfaces?.[surface] === false);
|
|
25
|
+
}
|
|
26
|
+
const UNREAD_DESTINATION_REGISTRY = {
|
|
27
|
+
entries: [],
|
|
28
|
+
intern: () => void 0
|
|
29
|
+
};
|
|
30
|
+
function resolvePageSelection(selection, pageCount) {
|
|
31
|
+
const resolved = /* @__PURE__ */ new Set();
|
|
32
|
+
for (const requested of selection) {
|
|
33
|
+
const index = requested < 0 ? pageCount + requested : requested;
|
|
34
|
+
if (!Number.isInteger(requested) || index < 0 || index >= pageCount) throw new require_diagnostics.PdfPageSelectionError(requested, pageCount);
|
|
35
|
+
resolved.add(index);
|
|
36
|
+
}
|
|
37
|
+
return resolved;
|
|
38
|
+
}
|
|
23
39
|
const PDF_HEADER_BYTES = new TextEncoder().encode("%PDF-");
|
|
24
40
|
const HEADER_SEARCH_WINDOW = 1024;
|
|
25
41
|
const DEFAULT_PAGE_WIDTH_PT = 612;
|
|
@@ -45,21 +61,28 @@ function readPdf(bytes, options) {
|
|
|
45
61
|
const images = {};
|
|
46
62
|
const imageIdCache = /* @__PURE__ */ new Map();
|
|
47
63
|
const pageDicts = doc.pages();
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const
|
|
64
|
+
const selection = options?.pages === void 0 ? void 0 : resolvePageSelection(options.pages, pageDicts.length);
|
|
65
|
+
const skippedSurfaces = skippedSurfacesOf(options?.surfaces);
|
|
66
|
+
const reads = (surface) => !skippedSurfaces.includes(surface);
|
|
67
|
+
const destinationRegistry = reads("destinations") ? require_navigation.createDestinationRegistry(doc.catalog, doc, (obj) => doc.pageIndex(obj), sink) : UNREAD_DESTINATION_REGISTRY;
|
|
68
|
+
const outline = reads("outline") ? require_navigation.readOutline(doc.catalog, destinationRegistry, doc, sink) : void 0;
|
|
69
|
+
const attachments = selection === void 0 ? require_attachments.readAttachments(doc.catalog, pageDicts, doc, sink) : [];
|
|
70
|
+
const optionalContent = reads("layers") ? require_optional_content.readOptionalContent(doc.catalog, doc, sink) : void 0;
|
|
71
|
+
const form = reads("form") ? require_form.readAcroForm(doc.catalog, doc, (obj) => doc.pageIndex(obj), sink) : void 0;
|
|
72
|
+
const structure = reads("structure") ? require_structure.readStructure(doc.catalog, pageDicts, (index) => selection === void 0 || selection.has(index), doc, sink) : void 0;
|
|
73
|
+
const source = reads("residue") ? readDocumentResidue(doc, sink) : void 0;
|
|
55
74
|
const pageBoxRows = [];
|
|
56
|
-
const pages = pageDicts.
|
|
75
|
+
const pages = pageDicts.flatMap((pageDict, index) => {
|
|
76
|
+
if (selection !== void 0 && !selection.has(index)) return [];
|
|
57
77
|
require_util_abort.throwIfAborted(signal);
|
|
58
|
-
const read = readPage(index, pageDict, doc, fontResolver, images, imageIdCache, destinationRegistry, optionalContent
|
|
78
|
+
const read = readPage(index, pageDict, doc, fontResolver, images, imageIdCache, destinationRegistry, optionalContent?.layerNameOf ?? noLayerName, structure?.ownerOf ?? noStructureOwner, sink);
|
|
59
79
|
if (read.boxRow !== void 0) pageBoxRows.push(read.boxRow);
|
|
60
|
-
return read.page
|
|
80
|
+
return [selection === void 0 ? read.page : {
|
|
81
|
+
...read.page,
|
|
82
|
+
index
|
|
83
|
+
}];
|
|
61
84
|
});
|
|
62
|
-
if (pageBoxRows.length > 0) source["page-boxes"] = {
|
|
85
|
+
if (source !== void 0 && pageBoxRows.length > 0) source["page-boxes"] = {
|
|
63
86
|
format: "pdf",
|
|
64
87
|
xml: require_serialize.serializeObjectToText(require_objects.pdfArray(pageBoxRows))
|
|
65
88
|
};
|
|
@@ -67,16 +90,20 @@ function readPdf(bytes, options) {
|
|
|
67
90
|
formatVersion: 1,
|
|
68
91
|
metadata: readMetadata(doc.trailer, doc, doc.catalog, sink),
|
|
69
92
|
pages,
|
|
93
|
+
...selection !== void 0 ? { pageCount: pageDicts.length } : {},
|
|
70
94
|
images,
|
|
71
95
|
...destinationRegistry.entries.length > 0 ? { destinations: [...destinationRegistry.entries] } : {},
|
|
72
|
-
...outline.length > 0 ? { outline } : {},
|
|
96
|
+
...outline !== void 0 && outline.length > 0 ? { outline } : {},
|
|
73
97
|
...attachments.length > 0 ? { attachments } : {},
|
|
74
|
-
...optionalContent.layers.length > 0 ? { layers: [...optionalContent.layers] } : {},
|
|
75
|
-
...form.length > 0 ? { form } : {},
|
|
76
|
-
...structure.tree.length > 0 ? { structure: [...structure.tree] } : {},
|
|
77
|
-
...Object.keys(source).length > 0 ? { source } : {}
|
|
98
|
+
...optionalContent !== void 0 && optionalContent.layers.length > 0 ? { layers: [...optionalContent.layers] } : {},
|
|
99
|
+
...form !== void 0 && form.length > 0 ? { form } : {},
|
|
100
|
+
...structure !== void 0 && structure.tree.length > 0 ? { structure: [...structure.tree] } : {},
|
|
101
|
+
...source !== void 0 && Object.keys(source).length > 0 ? { source } : {},
|
|
102
|
+
...skippedSurfaces.length > 0 ? { skippedSurfaces } : {}
|
|
78
103
|
};
|
|
79
104
|
}
|
|
105
|
+
function noLayerName() {}
|
|
106
|
+
function noStructureOwner() {}
|
|
80
107
|
function readDeclaredPageBox(page, key) {
|
|
81
108
|
const arr = require_objects.asArray(require_objects.dictGet(page, key));
|
|
82
109
|
if (arr === void 0) return;
|
package/dist/read.d.cts
CHANGED
|
@@ -1,11 +1,40 @@
|
|
|
1
|
-
import { i as PdfDiagnosticSink } from "./diagnostics-
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-BkG_Ej2x.cjs";
|
|
2
2
|
import { r as Matrix } from "./matrix-B7_SBKQ5.cjs";
|
|
3
|
-
import { LayoutDocument } from "./layout.cjs";
|
|
3
|
+
import { LayoutDocument, LayoutDocumentSurface } from "./layout.cjs";
|
|
4
4
|
//#region src/read.d.ts
|
|
5
5
|
interface ReadPdfOptions {
|
|
6
6
|
readonly sink?: PdfDiagnosticSink;
|
|
7
7
|
readonly signal?: AbortSignal;
|
|
8
|
+
/**
|
|
9
|
+
* The pages to read, as zero-based indices into the document's page tree; a negative index counts from the end (`-1` is the last page). Omitted, every page is read.
|
|
10
|
+
*
|
|
11
|
+
* What a selected read skips: an unselected page's content stream is never fetched, decoded or interpreted, so the fonts and images only unselected pages use are never resolved; embedded-file payloads are never decoded, so `attachments` is absent from a page-selected result (an attachment is document-level payload whose size is independent of the pages asked for, and decoding it would cost the same whichever pages were selected).
|
|
12
|
+
*
|
|
13
|
+
* What it still reads whole, because a negative index and every document-level page reference resolve against it or because it is document-level and holds no page content stream: the page tree, the outline, named destinations, optional-content layers, the AcroForm, the structure element tree and the /ParentTree number tree (both of which scale with the document), metadata and package residue; every one of those but the page tree and metadata can be left out as well with `surfaces`. Two surfaces are built from page content and so cover selected pages only: the structure-ownership association an item's `structure` field names (and its parent-tree diagnostics), and the `page-boxes` residue row. Destinations a link states as a direct array are minted into `destinations` (as `dest1`, `dest2`, ...) only when their page is interpreted, so an unselected page's direct link destinations are absent and a minted name depends on which pages were read (and on whether the outline was read: see `surfaces`); named destinations are unaffected.
|
|
14
|
+
*
|
|
15
|
+
* Duplicates collapse, and the result's `pages` holds the selected pages in ascending document order whatever order they were asked for in, each carrying its source position as `index`, with the document's total as `pageCount`; every document-level reference keeps naming source indices. An empty array is a valid selection: it reads no page and returns the document-level surfaces with `pageCount`, the cheapest way to learn a file's length and metadata. An entry naming no page throws `PdfPageSelectionError` rather than being skipped.
|
|
16
|
+
*/
|
|
17
|
+
readonly pages?: readonly number[];
|
|
18
|
+
/**
|
|
19
|
+
* Which document-level surfaces to read. Each is read unless its entry is `false`, so omitting the setting, or an entry, reads it as before. Independent of `pages`: it applies to a full read and a page-selected read alike.
|
|
20
|
+
*
|
|
21
|
+
* A surface turned off is never parsed (its part of the catalog is not walked, so a malformed outline, form, layer list or structure tree reports no diagnostic) and its field is absent from the result whatever the file holds; the result lists it in `skippedSurfaces`, which is how a caller tells "not read" from "none". What each one covers, and what page items lose without it:
|
|
22
|
+
*
|
|
23
|
+
* - `outline`: the `/Outlines` bookmark tree (`outline`). Page items do not depend on it, except through minted names: a destination stated as a direct array is named with the first unused `destN` in the order the reader meets it, and the outline is read before any page, so an outline entry's direct destination takes a lower number than any link's. Without the outline, the names minted for page links' direct destinations are renumbered, and `destinations` loses the entries only the outline minted; each link still resolves to the same target.
|
|
24
|
+
* - `destinations`: the named destinations of the catalog `/Dests` dictionary and the `/Names /Dests` name tree, and the registry links and outline entries name their targets through (`destinations`). Without it nothing can name an internal target, so a link whose target is internal (a `/Dest`, or a `/GoTo` action, named or direct) is left out of its page's items, and a read outline entry carries no `destination`; a link to a URI is kept as usual.
|
|
25
|
+
* - `form`: the AcroForm field tree (`form`). Page items do not depend on it: a widget annotation is never a page item or annotation either way.
|
|
26
|
+
* - `layers`: optional content, the `/OCProperties` groups and their default visibility (`layers`). Without it no item carries a `layer`, since an `/OC` membership resolves to no name; the items themselves are all still read, so content the default view hides is indistinguishable from visible content.
|
|
27
|
+
* - `structure`: the `/StructTreeRoot` element tree and its `/ParentTree` ownership map (`structure`). Without it no item carries a `structure` owner, and the parent-tree diagnostics are not reported.
|
|
28
|
+
* - `residue`: the package-level residue rows (`source`), including the per-page `page-boxes` row. Page items do not depend on it; `metadata` still reads the XMP packet it falls back to.
|
|
29
|
+
*
|
|
30
|
+
* Apart from those stated losses and the renumbering a skipped outline causes, every page item is exactly what a read with the surface on produces.
|
|
31
|
+
*/
|
|
32
|
+
readonly surfaces?: ReadPdfSurfaces;
|
|
8
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* One entry per document-level surface `readPdf` can leave out, each read unless set to `false` (see `ReadPdfOptions.surfaces` for what each covers and what page items lose without it).
|
|
36
|
+
*/
|
|
37
|
+
type ReadPdfSurfaces = Readonly<Partial<Record<LayoutDocumentSurface, boolean>>>;
|
|
9
38
|
declare function readPdf(bytes: Uint8Array<ArrayBuffer>, options?: ReadPdfOptions): LayoutDocument;
|
|
10
39
|
type PageRotation = 0 | 90 | 180 | 270;
|
|
11
40
|
declare function normalizeRotation(rotate: number | undefined): PageRotation;
|
|
@@ -16,4 +45,4 @@ interface PageRotationResult {
|
|
|
16
45
|
}
|
|
17
46
|
declare function pageRotationTransform(rotation: PageRotation, w: number, h: number): PageRotationResult;
|
|
18
47
|
//#endregion
|
|
19
|
-
export { ReadPdfOptions, normalizeRotation, pageRotationTransform, readPdf };
|
|
48
|
+
export { ReadPdfOptions, ReadPdfSurfaces, normalizeRotation, pageRotationTransform, readPdf };
|
package/dist/read.d.ts
CHANGED
|
@@ -1,11 +1,40 @@
|
|
|
1
|
-
import { i as PdfDiagnosticSink } from "./diagnostics-
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-BkG_Ej2x.js";
|
|
2
2
|
import { r as Matrix } from "./matrix-B7_SBKQ5.js";
|
|
3
|
-
import { LayoutDocument } from "./layout.js";
|
|
3
|
+
import { LayoutDocument, LayoutDocumentSurface } from "./layout.js";
|
|
4
4
|
//#region src/read.d.ts
|
|
5
5
|
interface ReadPdfOptions {
|
|
6
6
|
readonly sink?: PdfDiagnosticSink;
|
|
7
7
|
readonly signal?: AbortSignal;
|
|
8
|
+
/**
|
|
9
|
+
* The pages to read, as zero-based indices into the document's page tree; a negative index counts from the end (`-1` is the last page). Omitted, every page is read.
|
|
10
|
+
*
|
|
11
|
+
* What a selected read skips: an unselected page's content stream is never fetched, decoded or interpreted, so the fonts and images only unselected pages use are never resolved; embedded-file payloads are never decoded, so `attachments` is absent from a page-selected result (an attachment is document-level payload whose size is independent of the pages asked for, and decoding it would cost the same whichever pages were selected).
|
|
12
|
+
*
|
|
13
|
+
* What it still reads whole, because a negative index and every document-level page reference resolve against it or because it is document-level and holds no page content stream: the page tree, the outline, named destinations, optional-content layers, the AcroForm, the structure element tree and the /ParentTree number tree (both of which scale with the document), metadata and package residue; every one of those but the page tree and metadata can be left out as well with `surfaces`. Two surfaces are built from page content and so cover selected pages only: the structure-ownership association an item's `structure` field names (and its parent-tree diagnostics), and the `page-boxes` residue row. Destinations a link states as a direct array are minted into `destinations` (as `dest1`, `dest2`, ...) only when their page is interpreted, so an unselected page's direct link destinations are absent and a minted name depends on which pages were read (and on whether the outline was read: see `surfaces`); named destinations are unaffected.
|
|
14
|
+
*
|
|
15
|
+
* Duplicates collapse, and the result's `pages` holds the selected pages in ascending document order whatever order they were asked for in, each carrying its source position as `index`, with the document's total as `pageCount`; every document-level reference keeps naming source indices. An empty array is a valid selection: it reads no page and returns the document-level surfaces with `pageCount`, the cheapest way to learn a file's length and metadata. An entry naming no page throws `PdfPageSelectionError` rather than being skipped.
|
|
16
|
+
*/
|
|
17
|
+
readonly pages?: readonly number[];
|
|
18
|
+
/**
|
|
19
|
+
* Which document-level surfaces to read. Each is read unless its entry is `false`, so omitting the setting, or an entry, reads it as before. Independent of `pages`: it applies to a full read and a page-selected read alike.
|
|
20
|
+
*
|
|
21
|
+
* A surface turned off is never parsed (its part of the catalog is not walked, so a malformed outline, form, layer list or structure tree reports no diagnostic) and its field is absent from the result whatever the file holds; the result lists it in `skippedSurfaces`, which is how a caller tells "not read" from "none". What each one covers, and what page items lose without it:
|
|
22
|
+
*
|
|
23
|
+
* - `outline`: the `/Outlines` bookmark tree (`outline`). Page items do not depend on it, except through minted names: a destination stated as a direct array is named with the first unused `destN` in the order the reader meets it, and the outline is read before any page, so an outline entry's direct destination takes a lower number than any link's. Without the outline, the names minted for page links' direct destinations are renumbered, and `destinations` loses the entries only the outline minted; each link still resolves to the same target.
|
|
24
|
+
* - `destinations`: the named destinations of the catalog `/Dests` dictionary and the `/Names /Dests` name tree, and the registry links and outline entries name their targets through (`destinations`). Without it nothing can name an internal target, so a link whose target is internal (a `/Dest`, or a `/GoTo` action, named or direct) is left out of its page's items, and a read outline entry carries no `destination`; a link to a URI is kept as usual.
|
|
25
|
+
* - `form`: the AcroForm field tree (`form`). Page items do not depend on it: a widget annotation is never a page item or annotation either way.
|
|
26
|
+
* - `layers`: optional content, the `/OCProperties` groups and their default visibility (`layers`). Without it no item carries a `layer`, since an `/OC` membership resolves to no name; the items themselves are all still read, so content the default view hides is indistinguishable from visible content.
|
|
27
|
+
* - `structure`: the `/StructTreeRoot` element tree and its `/ParentTree` ownership map (`structure`). Without it no item carries a `structure` owner, and the parent-tree diagnostics are not reported.
|
|
28
|
+
* - `residue`: the package-level residue rows (`source`), including the per-page `page-boxes` row. Page items do not depend on it; `metadata` still reads the XMP packet it falls back to.
|
|
29
|
+
*
|
|
30
|
+
* Apart from those stated losses and the renumbering a skipped outline causes, every page item is exactly what a read with the surface on produces.
|
|
31
|
+
*/
|
|
32
|
+
readonly surfaces?: ReadPdfSurfaces;
|
|
8
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* One entry per document-level surface `readPdf` can leave out, each read unless set to `false` (see `ReadPdfOptions.surfaces` for what each covers and what page items lose without it).
|
|
36
|
+
*/
|
|
37
|
+
type ReadPdfSurfaces = Readonly<Partial<Record<LayoutDocumentSurface, boolean>>>;
|
|
9
38
|
declare function readPdf(bytes: Uint8Array<ArrayBuffer>, options?: ReadPdfOptions): LayoutDocument;
|
|
10
39
|
type PageRotation = 0 | 90 | 180 | 270;
|
|
11
40
|
declare function normalizeRotation(rotate: number | undefined): PageRotation;
|
|
@@ -16,4 +45,4 @@ interface PageRotationResult {
|
|
|
16
45
|
}
|
|
17
46
|
declare function pageRotationTransform(rotation: PageRotation, w: number, h: number): PageRotationResult;
|
|
18
47
|
//#endregion
|
|
19
|
-
export { ReadPdfOptions, normalizeRotation, pageRotationTransform, readPdf };
|
|
48
|
+
export { ReadPdfOptions, ReadPdfSurfaces, normalizeRotation, pageRotationTransform, readPdf };
|