pdf-parser.js 5.2.26 → 5.2.28
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/dist/{afm-widths-BYiX2L9D.cjs → afm-widths-BHD2HZIL.cjs} +553 -642
- package/dist/{afm-widths-blUDDjlI.js → afm-widths-B_IGbGky.js} +553 -642
- package/dist/afm-widths.cjs +1 -1
- package/dist/afm-widths.js +1 -1
- package/dist/annotations.cjs +5 -3
- package/dist/annotations.d.cts +2 -2
- package/dist/annotations.d.ts +2 -2
- package/dist/annotations.js +5 -3
- package/dist/attachments.d.cts +2 -2
- package/dist/attachments.d.ts +2 -2
- package/dist/builtin-encoding.cjs +17 -6
- package/dist/builtin-encoding.js +17 -6
- package/dist/bytes/crc32.cjs +5 -3
- package/dist/bytes/crc32.js +5 -3
- package/dist/bytes/flate.cjs +0 -1
- package/dist/bytes/flate.js +0 -1
- package/dist/cff-bounds.cjs +73 -45
- package/dist/cff-bounds.js +73 -45
- package/dist/cff.cjs +13 -6
- package/dist/cff.js +13 -6
- package/dist/cmap-table.cjs +54 -26
- package/dist/cmap-table.js +54 -26
- package/dist/cmap.cjs +5 -3
- package/dist/cmap.js +5 -3
- package/dist/content-read.d.cts +1 -1
- package/dist/content-read.d.ts +1 -1
- package/dist/content-write.cjs +21 -14
- package/dist/content-write.d.cts +2 -2
- package/dist/content-write.d.ts +2 -2
- package/dist/content-write.js +21 -14
- package/dist/crypto/aes.cjs +76 -55
- package/dist/crypto/aes.js +76 -55
- package/dist/crypto/md5.cjs +345 -149
- package/dist/crypto/md5.js +345 -149
- package/dist/crypto/rc4.cjs +5 -4
- package/dist/crypto/rc4.js +5 -4
- package/dist/crypto/sha2.cjs +92 -43
- package/dist/crypto/sha2.js +92 -43
- package/dist/document.cjs +17 -11
- package/dist/document.d.cts +1 -1
- package/dist/document.d.ts +1 -1
- package/dist/document.js +17 -11
- package/dist/{embedded-font-Bnhh4juV.d.ts → embedded-font-ByD7ZiQS.d.ts} +1 -1
- package/dist/{embedded-font-CEf-zBCA.d.cts → embedded-font-DgVBedw6.d.cts} +1 -1
- package/dist/embedded-font-write.d.cts +2 -2
- package/dist/embedded-font-write.d.ts +2 -2
- package/dist/embedded-font.cjs +4 -2
- package/dist/embedded-font.d.cts +1 -1
- package/dist/embedded-font.d.ts +1 -1
- package/dist/embedded-font.js +4 -2
- package/dist/encoding.cjs +1 -1
- package/dist/encoding.js +1 -1
- package/dist/encrypt-write.cjs +25 -21
- package/dist/encrypt-write.d.cts +1 -1
- package/dist/encrypt-write.d.ts +1 -1
- package/dist/encrypt-write.js +25 -21
- package/dist/encrypt.cjs +43 -64
- package/dist/encrypt.d.cts +1 -1
- package/dist/encrypt.d.ts +1 -1
- package/dist/encrypt.js +43 -64
- package/dist/filters.cjs +46 -26
- package/dist/filters.d.cts +1 -1
- package/dist/filters.d.ts +1 -1
- package/dist/filters.js +46 -26
- package/dist/font-face.cjs +2 -1
- package/dist/font-face.js +2 -1
- package/dist/font-read.cjs +12 -6
- package/dist/font-read.d.cts +1 -1
- package/dist/font-read.d.ts +1 -1
- package/dist/font-read.js +12 -6
- package/dist/font-registry.d.cts +3 -3
- package/dist/font-registry.d.ts +3 -3
- package/dist/font-tables.cjs +55 -28
- package/dist/font-tables.js +55 -28
- package/dist/form.cjs +13 -8
- package/dist/form.d.cts +2 -2
- package/dist/form.d.ts +2 -2
- package/dist/form.js +13 -8
- package/dist/gdef-table.cjs +6 -3
- package/dist/gdef-table.js +6 -3
- package/dist/{glyf-contours-C0epBNqP.d.ts → glyf-contours-B1PsI9oA.d.ts} +1 -1
- package/dist/{glyf-contours-BRpvd0rt.d.cts → glyf-contours-NHBpgks-.d.cts} +1 -1
- package/dist/glyf-contours.cjs +3 -1
- package/dist/glyf-contours.d.cts +1 -1
- package/dist/glyf-contours.d.ts +1 -1
- package/dist/glyf-contours.js +3 -1
- package/dist/glyf.cjs +22 -11
- package/dist/glyf.js +22 -11
- package/dist/gpos-table.cjs +37 -19
- package/dist/gpos-table.js +37 -19
- package/dist/gsub-table.cjs +40 -25
- package/dist/gsub-table.js +40 -25
- package/dist/hmtx-table.cjs +5 -3
- package/dist/hmtx-table.js +5 -3
- package/dist/image/ccitt-encode.cjs +8 -5
- package/dist/image/ccitt-encode.js +8 -5
- package/dist/image/ccitt.cjs +801 -209
- package/dist/image/ccitt.js +801 -209
- package/dist/image/jbig2-arith.cjs +340 -306
- package/dist/image/jbig2-arith.js +340 -306
- package/dist/image/jbig2-bitmap.cjs +8 -5
- package/dist/image/jbig2-bitmap.js +8 -5
- package/dist/image/jbig2-generic.cjs +240 -69
- package/dist/image/jbig2-generic.js +240 -69
- package/dist/image/jbig2-text.cjs +4 -2
- package/dist/image/jbig2-text.js +4 -2
- package/dist/image/jbig2.cjs +69 -31
- package/dist/image/jbig2.js +69 -31
- package/dist/image/jp2-boxes.cjs +52 -27
- package/dist/image/jp2-boxes.js +52 -27
- package/dist/image/jpeg-info.cjs +29 -24
- package/dist/image/jpeg-info.js +29 -24
- package/dist/image/jpeg2000-codestream.cjs +61 -32
- package/dist/image/jpeg2000-codestream.js +61 -32
- package/dist/image/jpeg2000-dwt.cjs +2 -1
- package/dist/image/jpeg2000-dwt.js +2 -1
- package/dist/image/jpeg2000-t1.cjs +21 -11
- package/dist/image/jpeg2000-t1.js +21 -11
- package/dist/image/jpeg2000-t2.cjs +12 -5
- package/dist/image/jpeg2000-t2.js +12 -5
- package/dist/image/jpeg2000-tagtree.cjs +8 -4
- package/dist/image/jpeg2000-tagtree.js +8 -4
- package/dist/image/jpeg2000.cjs +11 -6
- package/dist/image/jpeg2000.js +11 -6
- package/dist/image/png-decode.cjs +62 -39
- package/dist/image/png-decode.d.cts +3 -2
- package/dist/image/png-decode.d.ts +3 -2
- package/dist/image/png-decode.js +62 -39
- package/dist/image/png-filter.cjs +23 -15
- package/dist/image/png-filter.js +23 -15
- package/dist/images-read.cjs +41 -36
- package/dist/images-read.d.cts +2 -2
- package/dist/images-read.d.ts +2 -2
- package/dist/images-read.js +41 -36
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/interpret.cjs +68 -40
- package/dist/interpret.d.cts +1 -1
- package/dist/interpret.d.ts +1 -1
- package/dist/interpret.js +68 -40
- package/dist/lexer.cjs +86 -51
- package/dist/lexer.js +86 -51
- package/dist/math-content-write.cjs +9 -5
- package/dist/math-content-write.js +9 -5
- package/dist/math-font-write.cjs +2 -1
- package/dist/math-font-write.d.cts +1 -1
- package/dist/math-font-write.d.ts +1 -1
- package/dist/math-font-write.js +2 -1
- package/dist/math-font.cjs +16 -7
- package/dist/math-font.js +16 -7
- package/dist/math-table.cjs +25 -13
- package/dist/math-table.js +25 -13
- package/dist/matrix.cjs +3 -2
- package/dist/matrix.js +3 -2
- package/dist/measure.cjs +1 -1
- package/dist/measure.js +1 -1
- package/dist/names.cjs +7 -7
- package/dist/names.d.cts +2 -2
- package/dist/names.d.ts +2 -2
- package/dist/names.js +7 -7
- package/dist/navigation.cjs +16 -12
- package/dist/navigation.d.cts +4 -4
- package/dist/navigation.d.ts +4 -4
- package/dist/navigation.js +16 -12
- package/dist/{objects-B7HdMeWS.d.cts → objects-e2RS3-yT.d.cts} +3 -3
- package/dist/{objects-B7HdMeWS.d.ts → objects-e2RS3-yT.d.ts} +3 -3
- package/dist/objects.d.cts +1 -1
- package/dist/objects.d.ts +1 -1
- package/dist/optional-content.d.cts +2 -2
- package/dist/optional-content.d.ts +2 -2
- package/dist/ot-layout-common.cjs +22 -15
- package/dist/ot-layout-common.js +22 -15
- package/dist/parse.cjs +7 -5
- package/dist/parse.d.cts +1 -1
- package/dist/parse.d.ts +1 -1
- package/dist/parse.js +7 -5
- package/dist/pdf-text.cjs +5 -2
- package/dist/pdf-text.js +5 -2
- package/dist/predictors.cjs +14 -9
- package/dist/predictors.d.cts +1 -1
- package/dist/predictors.d.ts +1 -1
- package/dist/predictors.js +14 -9
- package/dist/raster.cjs +30 -19
- package/dist/raster.d.cts +8 -8
- package/dist/raster.d.ts +8 -8
- package/dist/raster.js +30 -19
- package/dist/read.cjs +29 -16
- package/dist/read.js +29 -16
- package/dist/serialize.cjs +6 -2
- package/dist/serialize.d.cts +1 -1
- package/dist/serialize.d.ts +1 -1
- package/dist/serialize.js +6 -2
- package/dist/sfnt-subset.cjs +25 -13
- package/dist/sfnt-subset.d.cts +1 -1
- package/dist/sfnt-subset.d.ts +1 -1
- package/dist/sfnt-subset.js +25 -13
- package/dist/sfnt.cjs +20 -10
- package/dist/sfnt.js +20 -10
- package/dist/structure.d.cts +2 -2
- package/dist/structure.d.ts +2 -2
- package/dist/text-group.cjs +0 -1
- package/dist/text-group.js +0 -1
- package/dist/text-layout.d.cts +1 -1
- package/dist/text-layout.d.ts +1 -1
- package/dist/tounicode.cjs +4 -2
- package/dist/tounicode.d.cts +1 -1
- package/dist/tounicode.d.ts +1 -1
- package/dist/tounicode.js +4 -2
- package/dist/winansi.cjs +1 -1
- package/dist/winansi.js +1 -1
- package/dist/write.cjs +20 -12
- package/dist/write.d.cts +1 -1
- package/dist/write.d.ts +1 -1
- package/dist/write.js +20 -12
- package/dist/xref.cjs +5 -2
- package/dist/xref.d.cts +1 -1
- package/dist/xref.d.ts +1 -1
- package/dist/xref.js +5 -2
- package/package.json +1 -1
package/dist/text-group.cjs
CHANGED
package/dist/text-group.js
CHANGED
package/dist/text-layout.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Color, LayoutFont, StyledRun, TextMeasurer, WrapOptions, WrappedLine } from "document-schema.js";
|
|
2
2
|
//#region src/text-layout.d.ts
|
|
3
3
|
declare function wrapRunsToWidth(runs: readonly StyledRun[], measurer: TextMeasurer, maxWidthPt: number, options?: WrapOptions): WrappedLine[];
|
|
4
|
-
declare function wrapTextToWidth(text: string, font: LayoutFont
|
|
4
|
+
declare function wrapTextToWidth(text: string, font: Readonly<LayoutFont>, sizePt: number, color: Readonly<Color>, measurer: TextMeasurer, maxWidthPt: number): string[];
|
|
5
5
|
//#endregion
|
|
6
6
|
export { wrapRunsToWidth, wrapTextToWidth };
|
package/dist/text-layout.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Color, LayoutFont, StyledRun, TextMeasurer, WrapOptions, WrappedLine } from "document-schema.js";
|
|
2
2
|
//#region src/text-layout.d.ts
|
|
3
3
|
declare function wrapRunsToWidth(runs: readonly StyledRun[], measurer: TextMeasurer, maxWidthPt: number, options?: WrapOptions): WrappedLine[];
|
|
4
|
-
declare function wrapTextToWidth(text: string, font: LayoutFont
|
|
4
|
+
declare function wrapTextToWidth(text: string, font: Readonly<LayoutFont>, sizePt: number, color: Readonly<Color>, measurer: TextMeasurer, maxWidthPt: number): string[];
|
|
5
5
|
//#endregion
|
|
6
6
|
export { wrapRunsToWidth, wrapTextToWidth };
|
package/dist/tounicode.cjs
CHANGED
|
@@ -2,10 +2,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_objects = require("./objects.cjs");
|
|
3
3
|
//#region src/tounicode.ts
|
|
4
4
|
const MAX_BFCHAR_ENTRIES_PER_BLOCK = 100;
|
|
5
|
+
const HEX_RADIX = 16;
|
|
6
|
+
const UTF16_HEX_DIGIT_WIDTH = 4;
|
|
5
7
|
function codePointToUtf16BEHex(codePoint) {
|
|
6
8
|
const text = String.fromCodePoint(codePoint);
|
|
7
9
|
let hex = "";
|
|
8
|
-
for (let i = 0; i < text.length; i++) hex += text.charCodeAt(i).toString(
|
|
10
|
+
for (let i = 0; i < text.length; i++) hex += text.charCodeAt(i).toString(HEX_RADIX).padStart(UTF16_HEX_DIGIT_WIDTH, "0");
|
|
9
11
|
return hex;
|
|
10
12
|
}
|
|
11
13
|
function sequenceToUtf16BEHex(codePoints) {
|
|
@@ -29,7 +31,7 @@ function buildToUnicodeCMap(codeToSequence) {
|
|
|
29
31
|
for (let start = 0; start < entries.length; start += MAX_BFCHAR_ENTRIES_PER_BLOCK) {
|
|
30
32
|
const block = entries.slice(start, start + MAX_BFCHAR_ENTRIES_PER_BLOCK);
|
|
31
33
|
lines.push(`${block.length} beginbfchar`);
|
|
32
|
-
for (const [code, sequence] of block) lines.push(`<${code.toString(
|
|
34
|
+
for (const [code, sequence] of block) lines.push(`<${code.toString(HEX_RADIX).padStart(UTF16_HEX_DIGIT_WIDTH, "0")}> <${sequenceToUtf16BEHex(sequence)}>`);
|
|
33
35
|
lines.push("endbfchar");
|
|
34
36
|
}
|
|
35
37
|
lines.push("endcmap", "CMapName currentdict /CMap defineresource pop", "end", "end");
|
package/dist/tounicode.d.cts
CHANGED
package/dist/tounicode.d.ts
CHANGED
package/dist/tounicode.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { pdfDict, pdfStream } from "./objects.js";
|
|
2
2
|
//#region src/tounicode.ts
|
|
3
3
|
const MAX_BFCHAR_ENTRIES_PER_BLOCK = 100;
|
|
4
|
+
const HEX_RADIX = 16;
|
|
5
|
+
const UTF16_HEX_DIGIT_WIDTH = 4;
|
|
4
6
|
function codePointToUtf16BEHex(codePoint) {
|
|
5
7
|
const text = String.fromCodePoint(codePoint);
|
|
6
8
|
let hex = "";
|
|
7
|
-
for (let i = 0; i < text.length; i++) hex += text.charCodeAt(i).toString(
|
|
9
|
+
for (let i = 0; i < text.length; i++) hex += text.charCodeAt(i).toString(HEX_RADIX).padStart(UTF16_HEX_DIGIT_WIDTH, "0");
|
|
8
10
|
return hex;
|
|
9
11
|
}
|
|
10
12
|
function sequenceToUtf16BEHex(codePoints) {
|
|
@@ -28,7 +30,7 @@ function buildToUnicodeCMap(codeToSequence) {
|
|
|
28
30
|
for (let start = 0; start < entries.length; start += MAX_BFCHAR_ENTRIES_PER_BLOCK) {
|
|
29
31
|
const block = entries.slice(start, start + MAX_BFCHAR_ENTRIES_PER_BLOCK);
|
|
30
32
|
lines.push(`${block.length} beginbfchar`);
|
|
31
|
-
for (const [code, sequence] of block) lines.push(`<${code.toString(
|
|
33
|
+
for (const [code, sequence] of block) lines.push(`<${code.toString(HEX_RADIX).padStart(UTF16_HEX_DIGIT_WIDTH, "0")}> <${sequenceToUtf16BEHex(sequence)}>`);
|
|
32
34
|
lines.push("endbfchar");
|
|
33
35
|
}
|
|
34
36
|
lines.push("endcmap", "CMapName currentdict /CMap defineresource pop", "end", "end");
|
package/dist/winansi.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_afm_widths = require("./afm-widths-
|
|
2
|
+
const require_afm_widths = require("./afm-widths-BHD2HZIL.cjs");
|
|
3
3
|
exports.encodeForShow = require_afm_widths.encodeForShow;
|
|
4
4
|
exports.sanitizeToWinAnsi = require_afm_widths.sanitizeToWinAnsi;
|
|
5
5
|
exports.winAnsiCodeToUnicode = require_afm_widths.winAnsiCodeToUnicode;
|
package/dist/winansi.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as winAnsiCodeToUnicode, g as sanitizeToWinAnsi, h as encodeForShow } from "./afm-widths-
|
|
1
|
+
import { _ as winAnsiCodeToUnicode, g as sanitizeToWinAnsi, h as encodeForShow } from "./afm-widths-B_IGbGky.js";
|
|
2
2
|
export { encodeForShow, sanitizeToWinAnsi, winAnsiCodeToUnicode };
|
package/dist/write.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_afm_widths = require("./afm-widths-
|
|
2
|
+
const require_afm_widths = require("./afm-widths-BHD2HZIL.cjs");
|
|
3
3
|
const require_notes_annotation_author = require("./notes-annotation-author.cjs");
|
|
4
4
|
const require_objects = require("./objects.cjs");
|
|
5
5
|
const require_bytes_writer = require("./bytes/writer.cjs");
|
|
@@ -36,6 +36,11 @@ const FLAG_NONSYMBOLIC = 32;
|
|
|
36
36
|
const FLAG_ITALIC = 64;
|
|
37
37
|
const FLAG_FORCE_BOLD = 262144;
|
|
38
38
|
const FILE_ID_BYTES = 16;
|
|
39
|
+
const BITS_PER_BYTE = 8;
|
|
40
|
+
const BYTE_SHIFT = Math.log2(BITS_PER_BYTE);
|
|
41
|
+
const BYTE_MASK = 255;
|
|
42
|
+
const PACKED_BIT_MSB_MASK = 128;
|
|
43
|
+
const BIT_INDEX_MASK = 7;
|
|
39
44
|
function textToPdfString(text) {
|
|
40
45
|
const bytes = new Uint8Array(2 + text.length * 2);
|
|
41
46
|
bytes[0] = 254;
|
|
@@ -43,8 +48,8 @@ function textToPdfString(text) {
|
|
|
43
48
|
let offset = 2;
|
|
44
49
|
for (const unit of text.split("")) {
|
|
45
50
|
const code = unit.charCodeAt(0);
|
|
46
|
-
bytes[offset] = code >>
|
|
47
|
-
bytes[offset + 1] = code &
|
|
51
|
+
bytes[offset] = code >> BITS_PER_BYTE & BYTE_MASK;
|
|
52
|
+
bytes[offset + 1] = code & BYTE_MASK;
|
|
48
53
|
offset += 2;
|
|
49
54
|
}
|
|
50
55
|
return require_objects.pdfHexString(bytes);
|
|
@@ -108,9 +113,10 @@ function buildFontObjects(standardName, descriptorRef) {
|
|
|
108
113
|
function codePointsOf(texts) {
|
|
109
114
|
return new Set(texts.flatMap((text) => [...text].map((character) => character.codePointAt(0))));
|
|
110
115
|
}
|
|
116
|
+
const JPEG_COMPONENTS_CMYK = 4;
|
|
111
117
|
function prepareJpegImage(bytes) {
|
|
112
118
|
const info = require_image_jpeg_info.readJpegInfo(bytes);
|
|
113
|
-
const colorSpace = info.components === 1 ? "DeviceGray" : info.components ===
|
|
119
|
+
const colorSpace = info.components === 1 ? "DeviceGray" : info.components === JPEG_COMPONENTS_CMYK ? "DeviceCMYK" : "DeviceRGB";
|
|
114
120
|
const entries = /* @__PURE__ */ new Map([
|
|
115
121
|
["Type", require_objects.pdfName("XObject")],
|
|
116
122
|
["Subtype", require_objects.pdfName("Image")],
|
|
@@ -120,7 +126,7 @@ function prepareJpegImage(bytes) {
|
|
|
120
126
|
["BitsPerComponent", require_objects.pdfNum(info.precision)],
|
|
121
127
|
["Filter", require_objects.pdfName("DCTDecode")]
|
|
122
128
|
]);
|
|
123
|
-
if (info.components ===
|
|
129
|
+
if (info.components === JPEG_COMPONENTS_CMYK && (info.adobeTransform === 2 || info.adobeTransform === void 0)) entries.set("Decode", require_objects.pdfArray([
|
|
124
130
|
1,
|
|
125
131
|
0,
|
|
126
132
|
1,
|
|
@@ -142,22 +148,22 @@ function pngImageDict(width, height, colorSpace, compress) {
|
|
|
142
148
|
["Width", require_objects.pdfNum(width)],
|
|
143
149
|
["Height", require_objects.pdfNum(height)],
|
|
144
150
|
["ColorSpace", require_objects.pdfName(colorSpace)],
|
|
145
|
-
["BitsPerComponent", require_objects.pdfNum(
|
|
151
|
+
["BitsPerComponent", require_objects.pdfNum(BITS_PER_BYTE)]
|
|
146
152
|
]);
|
|
147
153
|
if (compress) entries.set("Filter", require_objects.pdfName("FlateDecode"));
|
|
148
154
|
return require_objects.pdfDict(entries);
|
|
149
155
|
}
|
|
150
156
|
function packBilevel(raw) {
|
|
151
|
-
const rowBytes = raw.width +
|
|
157
|
+
const rowBytes = raw.width + BIT_INDEX_MASK >> BYTE_SHIFT;
|
|
152
158
|
const packed = new Uint8Array(rowBytes * raw.height);
|
|
153
159
|
const view = new DataView(packed.buffer);
|
|
154
160
|
for (let index = 0; index < raw.data.length; index++) {
|
|
155
161
|
const sample = raw.data[index];
|
|
156
|
-
if (sample !== 0 && sample !==
|
|
157
|
-
if (sample ===
|
|
162
|
+
if (sample !== 0 && sample !== BYTE_MASK) return;
|
|
163
|
+
if (sample === BYTE_MASK) {
|
|
158
164
|
const x = index % raw.width;
|
|
159
|
-
const byteIndex = Math.floor(index / raw.width) * rowBytes + (x >>
|
|
160
|
-
view.setUint8(byteIndex, view.getUint8(byteIndex) |
|
|
165
|
+
const byteIndex = Math.floor(index / raw.width) * rowBytes + (x >> BYTE_SHIFT);
|
|
166
|
+
view.setUint8(byteIndex, view.getUint8(byteIndex) | PACKED_BIT_MSB_MASK >> (x & BIT_INDEX_MASK));
|
|
161
167
|
}
|
|
162
168
|
}
|
|
163
169
|
return packed;
|
|
@@ -323,8 +329,10 @@ function buildNotesAnnotDict(notes) {
|
|
|
323
329
|
F: require_objects.pdfNum(NOTES_ANNOTATION_HIDDEN_FLAG)
|
|
324
330
|
});
|
|
325
331
|
}
|
|
332
|
+
const XREF_OFFSET_DIGITS = 10;
|
|
333
|
+
const XREF_GENERATION_DIGITS = 5;
|
|
326
334
|
function xrefEntry(offset, generation, inUse) {
|
|
327
|
-
return `${offset.toString().padStart(
|
|
335
|
+
return `${offset.toString().padStart(XREF_OFFSET_DIGITS, "0")} ${generation.toString().padStart(XREF_GENERATION_DIGITS, "0")} ${inUse ? "n" : "f"} \n`;
|
|
328
336
|
}
|
|
329
337
|
function parseResidueRow(residue) {
|
|
330
338
|
const reader = new require_bytes_reader.ByteReader(new TextEncoder().encode(residue.xml));
|
package/dist/write.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LayoutDocument } from "./layout.cjs";
|
|
2
|
-
import { r as EmbeddedFaceSubstitution } from "./embedded-font-
|
|
2
|
+
import { r as EmbeddedFaceSubstitution } from "./embedded-font-DgVBedw6.cjs";
|
|
3
3
|
import { WinAnsiSubstitution } from "./winansi.cjs";
|
|
4
4
|
import { PdfEncryptionOptions } from "./encrypt-write.cjs";
|
|
5
5
|
import { FontRegistry } from "./font-registry.cjs";
|
package/dist/write.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LayoutDocument } from "./layout.js";
|
|
2
|
-
import { r as EmbeddedFaceSubstitution } from "./embedded-font-
|
|
2
|
+
import { r as EmbeddedFaceSubstitution } from "./embedded-font-ByD7ZiQS.js";
|
|
3
3
|
import { WinAnsiSubstitution } from "./winansi.js";
|
|
4
4
|
import { PdfEncryptionOptions } from "./encrypt-write.js";
|
|
5
5
|
import { FontRegistry } from "./font-registry.js";
|
package/dist/write.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as widthOfCode, t as STANDARD_METRICS } from "./afm-widths-
|
|
1
|
+
import { n as widthOfCode, t as STANDARD_METRICS } from "./afm-widths-B_IGbGky.js";
|
|
2
2
|
import { NOTES_ANNOTATION_AUTHOR } from "./notes-annotation-author.js";
|
|
3
3
|
import { pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream } from "./objects.js";
|
|
4
4
|
import { ByteWriter, concatBytes } from "./bytes/writer.js";
|
|
@@ -35,6 +35,11 @@ const FLAG_NONSYMBOLIC = 32;
|
|
|
35
35
|
const FLAG_ITALIC = 64;
|
|
36
36
|
const FLAG_FORCE_BOLD = 262144;
|
|
37
37
|
const FILE_ID_BYTES = 16;
|
|
38
|
+
const BITS_PER_BYTE = 8;
|
|
39
|
+
const BYTE_SHIFT = Math.log2(BITS_PER_BYTE);
|
|
40
|
+
const BYTE_MASK = 255;
|
|
41
|
+
const PACKED_BIT_MSB_MASK = 128;
|
|
42
|
+
const BIT_INDEX_MASK = 7;
|
|
38
43
|
function textToPdfString(text) {
|
|
39
44
|
const bytes = new Uint8Array(2 + text.length * 2);
|
|
40
45
|
bytes[0] = 254;
|
|
@@ -42,8 +47,8 @@ function textToPdfString(text) {
|
|
|
42
47
|
let offset = 2;
|
|
43
48
|
for (const unit of text.split("")) {
|
|
44
49
|
const code = unit.charCodeAt(0);
|
|
45
|
-
bytes[offset] = code >>
|
|
46
|
-
bytes[offset + 1] = code &
|
|
50
|
+
bytes[offset] = code >> BITS_PER_BYTE & BYTE_MASK;
|
|
51
|
+
bytes[offset + 1] = code & BYTE_MASK;
|
|
47
52
|
offset += 2;
|
|
48
53
|
}
|
|
49
54
|
return pdfHexString(bytes);
|
|
@@ -107,9 +112,10 @@ function buildFontObjects(standardName, descriptorRef) {
|
|
|
107
112
|
function codePointsOf(texts) {
|
|
108
113
|
return new Set(texts.flatMap((text) => [...text].map((character) => character.codePointAt(0))));
|
|
109
114
|
}
|
|
115
|
+
const JPEG_COMPONENTS_CMYK = 4;
|
|
110
116
|
function prepareJpegImage(bytes) {
|
|
111
117
|
const info = readJpegInfo$1(bytes);
|
|
112
|
-
const colorSpace = info.components === 1 ? "DeviceGray" : info.components ===
|
|
118
|
+
const colorSpace = info.components === 1 ? "DeviceGray" : info.components === JPEG_COMPONENTS_CMYK ? "DeviceCMYK" : "DeviceRGB";
|
|
113
119
|
const entries = /* @__PURE__ */ new Map([
|
|
114
120
|
["Type", pdfName("XObject")],
|
|
115
121
|
["Subtype", pdfName("Image")],
|
|
@@ -119,7 +125,7 @@ function prepareJpegImage(bytes) {
|
|
|
119
125
|
["BitsPerComponent", pdfNum(info.precision)],
|
|
120
126
|
["Filter", pdfName("DCTDecode")]
|
|
121
127
|
]);
|
|
122
|
-
if (info.components ===
|
|
128
|
+
if (info.components === JPEG_COMPONENTS_CMYK && (info.adobeTransform === 2 || info.adobeTransform === void 0)) entries.set("Decode", pdfArray([
|
|
123
129
|
1,
|
|
124
130
|
0,
|
|
125
131
|
1,
|
|
@@ -141,22 +147,22 @@ function pngImageDict(width, height, colorSpace, compress) {
|
|
|
141
147
|
["Width", pdfNum(width)],
|
|
142
148
|
["Height", pdfNum(height)],
|
|
143
149
|
["ColorSpace", pdfName(colorSpace)],
|
|
144
|
-
["BitsPerComponent", pdfNum(
|
|
150
|
+
["BitsPerComponent", pdfNum(BITS_PER_BYTE)]
|
|
145
151
|
]);
|
|
146
152
|
if (compress) entries.set("Filter", pdfName("FlateDecode"));
|
|
147
153
|
return pdfDict(entries);
|
|
148
154
|
}
|
|
149
155
|
function packBilevel(raw) {
|
|
150
|
-
const rowBytes = raw.width +
|
|
156
|
+
const rowBytes = raw.width + BIT_INDEX_MASK >> BYTE_SHIFT;
|
|
151
157
|
const packed = new Uint8Array(rowBytes * raw.height);
|
|
152
158
|
const view = new DataView(packed.buffer);
|
|
153
159
|
for (let index = 0; index < raw.data.length; index++) {
|
|
154
160
|
const sample = raw.data[index];
|
|
155
|
-
if (sample !== 0 && sample !==
|
|
156
|
-
if (sample ===
|
|
161
|
+
if (sample !== 0 && sample !== BYTE_MASK) return;
|
|
162
|
+
if (sample === BYTE_MASK) {
|
|
157
163
|
const x = index % raw.width;
|
|
158
|
-
const byteIndex = Math.floor(index / raw.width) * rowBytes + (x >>
|
|
159
|
-
view.setUint8(byteIndex, view.getUint8(byteIndex) |
|
|
164
|
+
const byteIndex = Math.floor(index / raw.width) * rowBytes + (x >> BYTE_SHIFT);
|
|
165
|
+
view.setUint8(byteIndex, view.getUint8(byteIndex) | PACKED_BIT_MSB_MASK >> (x & BIT_INDEX_MASK));
|
|
160
166
|
}
|
|
161
167
|
}
|
|
162
168
|
return packed;
|
|
@@ -322,8 +328,10 @@ function buildNotesAnnotDict(notes) {
|
|
|
322
328
|
F: pdfNum(NOTES_ANNOTATION_HIDDEN_FLAG)
|
|
323
329
|
});
|
|
324
330
|
}
|
|
331
|
+
const XREF_OFFSET_DIGITS = 10;
|
|
332
|
+
const XREF_GENERATION_DIGITS = 5;
|
|
325
333
|
function xrefEntry(offset, generation, inUse) {
|
|
326
|
-
return `${offset.toString().padStart(
|
|
334
|
+
return `${offset.toString().padStart(XREF_OFFSET_DIGITS, "0")} ${generation.toString().padStart(XREF_GENERATION_DIGITS, "0")} ${inUse ? "n" : "f"} \n`;
|
|
327
335
|
}
|
|
328
336
|
function parseResidueRow(residue) {
|
|
329
337
|
const reader = new ByteReader(new TextEncoder().encode(residue.xml));
|
package/dist/xref.cjs
CHANGED
|
@@ -220,9 +220,10 @@ function readXrefStreamSection(dict, raw, sink) {
|
|
|
220
220
|
prevOffset: require_objects.asNumber(require_objects.dictGet(dict, "Prev"))
|
|
221
221
|
};
|
|
222
222
|
}
|
|
223
|
+
const BYTE_RADIX = 256;
|
|
223
224
|
function readBigEndian(bytes, offset, width) {
|
|
224
225
|
let value = 0;
|
|
225
|
-
for (let i = 0; i < width; i++) value = value *
|
|
226
|
+
for (let i = 0; i < width; i++) value = value * BYTE_RADIX + (bytes[offset + i] ?? 0);
|
|
226
227
|
return value;
|
|
227
228
|
}
|
|
228
229
|
function isBoundaryByte(byte) {
|
|
@@ -238,8 +239,10 @@ function findAllKeywordPositions(bytes, needle) {
|
|
|
238
239
|
}
|
|
239
240
|
return positions;
|
|
240
241
|
}
|
|
242
|
+
const ASCII_DIGIT_ZERO = 48;
|
|
243
|
+
const ASCII_DIGIT_NINE = 57;
|
|
241
244
|
function isDigitByte(byte) {
|
|
242
|
-
return byte !== void 0 && byte >=
|
|
245
|
+
return byte !== void 0 && byte >= ASCII_DIGIT_ZERO && byte <= ASCII_DIGIT_NINE;
|
|
243
246
|
}
|
|
244
247
|
function scanBackWhile(bytes, end, predicate) {
|
|
245
248
|
let i = end;
|
package/dist/xref.d.cts
CHANGED
package/dist/xref.d.ts
CHANGED
package/dist/xref.js
CHANGED
|
@@ -219,9 +219,10 @@ function readXrefStreamSection(dict, raw, sink) {
|
|
|
219
219
|
prevOffset: asNumber(dictGet(dict, "Prev"))
|
|
220
220
|
};
|
|
221
221
|
}
|
|
222
|
+
const BYTE_RADIX = 256;
|
|
222
223
|
function readBigEndian(bytes, offset, width) {
|
|
223
224
|
let value = 0;
|
|
224
|
-
for (let i = 0; i < width; i++) value = value *
|
|
225
|
+
for (let i = 0; i < width; i++) value = value * BYTE_RADIX + (bytes[offset + i] ?? 0);
|
|
225
226
|
return value;
|
|
226
227
|
}
|
|
227
228
|
function isBoundaryByte(byte) {
|
|
@@ -237,8 +238,10 @@ function findAllKeywordPositions(bytes, needle) {
|
|
|
237
238
|
}
|
|
238
239
|
return positions;
|
|
239
240
|
}
|
|
241
|
+
const ASCII_DIGIT_ZERO = 48;
|
|
242
|
+
const ASCII_DIGIT_NINE = 57;
|
|
240
243
|
function isDigitByte(byte) {
|
|
241
|
-
return byte !== void 0 && byte >=
|
|
244
|
+
return byte !== void 0 && byte >= ASCII_DIGIT_ZERO && byte <= ASCII_DIGIT_NINE;
|
|
242
245
|
}
|
|
243
246
|
function scanBackWhile(bytes, end, predicate) {
|
|
244
247
|
let i = end;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-parser.js",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.28",
|
|
4
4
|
"description": "Hand-written, dependency-minimal PDF codec: parses arbitrary real-world PDFs and generates new ones, built on its own codec-owned LayoutDocument item model and Zod 4 codecs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|