pdf-parser.js 5.2.4 → 5.2.6

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 CHANGED
@@ -189,7 +189,7 @@ Reading a JPEG 2000 image directly, either as pixels or as metadata alone:
189
189
  ```ts
190
190
  import { decodeJpeg2000, readJpeg2000Metadata } from "pdf-codec";
191
191
 
192
- // Works on any conforming codestream -- including one whose pixels this decoder refuses, which is what `decodable`/`undecodableReason` are for.
192
+ // Works on any conforming codestream — including one whose pixels this decoder refuses, which is what `decodable`/`undecodableReason` are for.
193
193
  const metadata = readJpeg2000Metadata(jp2OrCodestreamBytes);
194
194
  console.log(
195
195
  metadata.width,
package/dist/write.cjs CHANGED
@@ -272,9 +272,9 @@ function destinationViewArray(target) {
272
272
  }
273
273
  function resolveDestinationArray(doc, pageAllocs, name, what) {
274
274
  const destination = doc.destinations?.find((d) => d.name === name);
275
- if (destination === void 0) throw new Error(`${what} names destination "${name}", which the document's destinations table does not carry -- this is a caller-invariant violation`);
275
+ if (destination === void 0) throw new Error(`${what} names destination "${name}", which the document's destinations table does not carry — this is a caller-invariant violation`);
276
276
  const targetPage = pageAllocs[destination.pageIndex];
277
- if (targetPage === void 0) throw new Error(`destination "${destination.name}" names page index ${destination.pageIndex}, which is beyond the document's own pages -- this is a caller-invariant violation`);
277
+ if (targetPage === void 0) throw new Error(`destination "${destination.name}" names page index ${destination.pageIndex}, which is beyond the document's own pages — this is a caller-invariant violation`);
278
278
  return [require_objects.pdfRef(targetPage.pageNum, 0), ...destinationViewArray(destination.target)];
279
279
  }
280
280
  function buildInternalLinkAnnotDict(link, doc, pageAllocs) {
@@ -452,7 +452,7 @@ function writePdf(doc, options = {}) {
452
452
  claimFormNums(doc.form ?? []);
453
453
  const formNumOf = (field) => {
454
454
  const num = formNumByField.get(field);
455
- if (num === void 0) throw new Error("AcroForm field object number was not claimed -- this is a writePdf internal invariant violation");
455
+ if (num === void 0) throw new Error("AcroForm field object number was not claimed — this is a writePdf internal invariant violation");
456
456
  return num;
457
457
  };
458
458
  const structElementNumById = /* @__PURE__ */ new Map();
@@ -690,11 +690,11 @@ function writePdf(doc, options = {}) {
690
690
  if (element.actualText !== void 0) entries.push(["ActualText", require_objects.pdfLiteralString(new TextEncoder().encode(element.actualText))]);
691
691
  if (element.children.length > 0) entries.push(["K", require_objects.pdfArray(element.children.map((child) => {
692
692
  const num = structElementNumById.get(child.id);
693
- if (num === void 0) throw new Error(`structure element "${child.id}" was not allocated -- this is a writePdf internal invariant violation`);
693
+ if (num === void 0) throw new Error(`structure element "${child.id}" was not allocated — this is a writePdf internal invariant violation`);
694
694
  return require_objects.pdfRef(num, 0);
695
695
  }))]);
696
696
  const ownNum = structElementNumById.get(element.id);
697
- if (ownNum === void 0) throw new Error(`structure element "${element.id}" was not allocated -- this is a writePdf internal invariant violation`);
697
+ if (ownNum === void 0) throw new Error(`structure element "${element.id}" was not allocated — this is a writePdf internal invariant violation`);
698
698
  objects.push({
699
699
  num: ownNum,
700
700
  value: require_objects.pdfDict(Object.fromEntries(entries))
@@ -775,7 +775,7 @@ function writePdf(doc, options = {}) {
775
775
  for (const [face, alloc] of embeddedAllocs) {
776
776
  const usedGlyphs = require_embedded_font.collectEmbeddedGlyphs(alloc.texts, face);
777
777
  const subset = require_sfnt_subset.subsetSfnt(face.font, [...alloc.codePoints].sort((a, b) => a - b), [...usedGlyphs.keys()].sort((a, b) => a - b));
778
- if (subset === void 0) throw new Error(`font "${face.postScriptName}" resolved to an embeddable face, but its glyph outlines could not be subsetted -- only TrueType-outline ('glyf') fonts can be embedded, so supply a TrueType face for this family or drop it from the registry`);
778
+ if (subset === void 0) throw new Error(`font "${face.postScriptName}" resolved to an embeddable face, but its glyph outlines could not be subsetted — only TrueType-outline ('glyf') fonts can be embedded, so supply a TrueType face for this family or drop it from the registry`);
779
779
  const built = require_embedded_font_write.buildEmbeddedFontObjects(face, subset, usedGlyphs, {
780
780
  cidFontRef: require_objects.pdfRef(alloc.cidFontNum, 0),
781
781
  descriptorRef: require_objects.pdfRef(alloc.descriptorNum, 0),
@@ -825,7 +825,7 @@ function writePdf(doc, options = {}) {
825
825
  const resolved = require_font_registry.resolveFaceWithRegistry(registry, font);
826
826
  if (resolved.kind === "embedded") {
827
827
  const alloc = embeddedAllocs.get(resolved.face);
828
- if (alloc === void 0) throw new Error(`embedded font "${resolved.face.postScriptName}" was not pre-allocated -- this is a writePdf internal invariant violation`);
828
+ if (alloc === void 0) throw new Error(`embedded font "${resolved.face.postScriptName}" was not pre-allocated — this is a writePdf internal invariant violation`);
829
829
  return {
830
830
  kind: "embedded",
831
831
  resourceName: alloc.resourceName,
@@ -833,7 +833,7 @@ function writePdf(doc, options = {}) {
833
833
  };
834
834
  }
835
835
  const alloc = fontAllocs.get(resolved.standardName);
836
- if (alloc === void 0) throw new Error(`font "${resolved.standardName}" was not pre-allocated -- this is a writePdf internal invariant violation`);
836
+ if (alloc === void 0) throw new Error(`font "${resolved.standardName}" was not pre-allocated — this is a writePdf internal invariant violation`);
837
837
  return {
838
838
  kind: "standard",
839
839
  resourceName: alloc.resourceName,
@@ -842,7 +842,7 @@ function writePdf(doc, options = {}) {
842
842
  },
843
843
  resolveImage: (imageId) => {
844
844
  const alloc = imageAllocs.get(imageId);
845
- if (alloc === void 0) throw new Error(`image "${imageId}" was not pre-allocated -- this is a writePdf internal invariant violation`);
845
+ if (alloc === void 0) throw new Error(`image "${imageId}" was not pre-allocated — this is a writePdf internal invariant violation`);
846
846
  return { resourceName: alloc.resourceName };
847
847
  }
848
848
  };
@@ -912,7 +912,7 @@ function writePdf(doc, options = {}) {
912
912
  ["Type", require_objects.pdfName("StructTreeRoot")],
913
913
  ["K", require_objects.pdfArray((doc.structure ?? []).map((element) => {
914
914
  const num = structElementNumById.get(element.id);
915
- if (num === void 0) throw new Error(`structure element "${element.id}" was not allocated -- this is a writePdf internal invariant violation`);
915
+ if (num === void 0) throw new Error(`structure element "${element.id}" was not allocated — this is a writePdf internal invariant violation`);
916
916
  return require_objects.pdfRef(num, 0);
917
917
  }))],
918
918
  ["ParentTree", require_objects.pdfRef(structParentTreeNum, 0)]
@@ -952,7 +952,7 @@ function writePdf(doc, options = {}) {
952
952
  writer.writeAscii(xrefEntry(0, 65535, false));
953
953
  for (let num = 1; num <= maxObjNum; num++) {
954
954
  const offset = offsets.get(num);
955
- if (offset === void 0) throw new Error(`object ${num} was allocated but never written -- this is a writePdf internal invariant violation`);
955
+ if (offset === void 0) throw new Error(`object ${num} was allocated but never written — this is a writePdf internal invariant violation`);
956
956
  writer.writeAscii(xrefEntry(offset, 0, true));
957
957
  }
958
958
  const trailerEntries = /* @__PURE__ */ new Map([
package/dist/write.js CHANGED
@@ -271,9 +271,9 @@ function destinationViewArray(target) {
271
271
  }
272
272
  function resolveDestinationArray(doc, pageAllocs, name, what) {
273
273
  const destination = doc.destinations?.find((d) => d.name === name);
274
- if (destination === void 0) throw new Error(`${what} names destination "${name}", which the document's destinations table does not carry -- this is a caller-invariant violation`);
274
+ if (destination === void 0) throw new Error(`${what} names destination "${name}", which the document's destinations table does not carry — this is a caller-invariant violation`);
275
275
  const targetPage = pageAllocs[destination.pageIndex];
276
- if (targetPage === void 0) throw new Error(`destination "${destination.name}" names page index ${destination.pageIndex}, which is beyond the document's own pages -- this is a caller-invariant violation`);
276
+ if (targetPage === void 0) throw new Error(`destination "${destination.name}" names page index ${destination.pageIndex}, which is beyond the document's own pages — this is a caller-invariant violation`);
277
277
  return [pdfRef(targetPage.pageNum, 0), ...destinationViewArray(destination.target)];
278
278
  }
279
279
  function buildInternalLinkAnnotDict(link, doc, pageAllocs) {
@@ -451,7 +451,7 @@ function writePdf(doc, options = {}) {
451
451
  claimFormNums(doc.form ?? []);
452
452
  const formNumOf = (field) => {
453
453
  const num = formNumByField.get(field);
454
- if (num === void 0) throw new Error("AcroForm field object number was not claimed -- this is a writePdf internal invariant violation");
454
+ if (num === void 0) throw new Error("AcroForm field object number was not claimed — this is a writePdf internal invariant violation");
455
455
  return num;
456
456
  };
457
457
  const structElementNumById = /* @__PURE__ */ new Map();
@@ -689,11 +689,11 @@ function writePdf(doc, options = {}) {
689
689
  if (element.actualText !== void 0) entries.push(["ActualText", pdfLiteralString(new TextEncoder().encode(element.actualText))]);
690
690
  if (element.children.length > 0) entries.push(["K", pdfArray(element.children.map((child) => {
691
691
  const num = structElementNumById.get(child.id);
692
- if (num === void 0) throw new Error(`structure element "${child.id}" was not allocated -- this is a writePdf internal invariant violation`);
692
+ if (num === void 0) throw new Error(`structure element "${child.id}" was not allocated — this is a writePdf internal invariant violation`);
693
693
  return pdfRef(num, 0);
694
694
  }))]);
695
695
  const ownNum = structElementNumById.get(element.id);
696
- if (ownNum === void 0) throw new Error(`structure element "${element.id}" was not allocated -- this is a writePdf internal invariant violation`);
696
+ if (ownNum === void 0) throw new Error(`structure element "${element.id}" was not allocated — this is a writePdf internal invariant violation`);
697
697
  objects.push({
698
698
  num: ownNum,
699
699
  value: pdfDict(Object.fromEntries(entries))
@@ -774,7 +774,7 @@ function writePdf(doc, options = {}) {
774
774
  for (const [face, alloc] of embeddedAllocs) {
775
775
  const usedGlyphs = collectEmbeddedGlyphs(alloc.texts, face);
776
776
  const subset = subsetSfnt(face.font, [...alloc.codePoints].sort((a, b) => a - b), [...usedGlyphs.keys()].sort((a, b) => a - b));
777
- if (subset === void 0) throw new Error(`font "${face.postScriptName}" resolved to an embeddable face, but its glyph outlines could not be subsetted -- only TrueType-outline ('glyf') fonts can be embedded, so supply a TrueType face for this family or drop it from the registry`);
777
+ if (subset === void 0) throw new Error(`font "${face.postScriptName}" resolved to an embeddable face, but its glyph outlines could not be subsetted — only TrueType-outline ('glyf') fonts can be embedded, so supply a TrueType face for this family or drop it from the registry`);
778
778
  const built = buildEmbeddedFontObjects(face, subset, usedGlyphs, {
779
779
  cidFontRef: pdfRef(alloc.cidFontNum, 0),
780
780
  descriptorRef: pdfRef(alloc.descriptorNum, 0),
@@ -824,7 +824,7 @@ function writePdf(doc, options = {}) {
824
824
  const resolved = resolveFaceWithRegistry(registry, font);
825
825
  if (resolved.kind === "embedded") {
826
826
  const alloc = embeddedAllocs.get(resolved.face);
827
- if (alloc === void 0) throw new Error(`embedded font "${resolved.face.postScriptName}" was not pre-allocated -- this is a writePdf internal invariant violation`);
827
+ if (alloc === void 0) throw new Error(`embedded font "${resolved.face.postScriptName}" was not pre-allocated — this is a writePdf internal invariant violation`);
828
828
  return {
829
829
  kind: "embedded",
830
830
  resourceName: alloc.resourceName,
@@ -832,7 +832,7 @@ function writePdf(doc, options = {}) {
832
832
  };
833
833
  }
834
834
  const alloc = fontAllocs.get(resolved.standardName);
835
- if (alloc === void 0) throw new Error(`font "${resolved.standardName}" was not pre-allocated -- this is a writePdf internal invariant violation`);
835
+ if (alloc === void 0) throw new Error(`font "${resolved.standardName}" was not pre-allocated — this is a writePdf internal invariant violation`);
836
836
  return {
837
837
  kind: "standard",
838
838
  resourceName: alloc.resourceName,
@@ -841,7 +841,7 @@ function writePdf(doc, options = {}) {
841
841
  },
842
842
  resolveImage: (imageId) => {
843
843
  const alloc = imageAllocs.get(imageId);
844
- if (alloc === void 0) throw new Error(`image "${imageId}" was not pre-allocated -- this is a writePdf internal invariant violation`);
844
+ if (alloc === void 0) throw new Error(`image "${imageId}" was not pre-allocated — this is a writePdf internal invariant violation`);
845
845
  return { resourceName: alloc.resourceName };
846
846
  }
847
847
  };
@@ -911,7 +911,7 @@ function writePdf(doc, options = {}) {
911
911
  ["Type", pdfName("StructTreeRoot")],
912
912
  ["K", pdfArray((doc.structure ?? []).map((element) => {
913
913
  const num = structElementNumById.get(element.id);
914
- if (num === void 0) throw new Error(`structure element "${element.id}" was not allocated -- this is a writePdf internal invariant violation`);
914
+ if (num === void 0) throw new Error(`structure element "${element.id}" was not allocated — this is a writePdf internal invariant violation`);
915
915
  return pdfRef(num, 0);
916
916
  }))],
917
917
  ["ParentTree", pdfRef(structParentTreeNum, 0)]
@@ -951,7 +951,7 @@ function writePdf(doc, options = {}) {
951
951
  writer.writeAscii(xrefEntry(0, 65535, false));
952
952
  for (let num = 1; num <= maxObjNum; num++) {
953
953
  const offset = offsets.get(num);
954
- if (offset === void 0) throw new Error(`object ${num} was allocated but never written -- this is a writePdf internal invariant violation`);
954
+ if (offset === void 0) throw new Error(`object ${num} was allocated but never written — this is a writePdf internal invariant violation`);
955
955
  writer.writeAscii(xrefEntry(offset, 0, true));
956
956
  }
957
957
  const trailerEntries = /* @__PURE__ */ new Map([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdf-parser.js",
3
- "version": "5.2.4",
3
+ "version": "5.2.6",
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": {
@@ -72,8 +72,8 @@
72
72
  ],
73
73
  "license": "MIT",
74
74
  "dependencies": {
75
- "byte-codec": "1.8.0",
76
- "document-schema.js": "7.14.0",
75
+ "byte-codec": "1.8.1",
76
+ "document-schema.js": "7.15.0",
77
77
  "fflate": "0.8.3",
78
78
  "zod": "4.4.3"
79
79
  },