@evotecit/officeimo 0.1.2 → 0.1.3

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 (37) hide show
  1. package/README.md +43 -49
  2. package/bundles/officeimo-canopyx.js +966 -122
  3. package/bundles/officeimo-canopyx.mjs +929 -92
  4. package/bundles/officeimo-csv.js +18 -15
  5. package/bundles/officeimo-csv.mjs +16 -13
  6. package/bundles/officeimo-datatables.js +168 -82
  7. package/bundles/officeimo-datatables.mjs +140 -54
  8. package/bundles/officeimo-pdf.js +148 -65
  9. package/bundles/officeimo-pdf.mjs +124 -41
  10. package/bundles/officeimo.js +168 -82
  11. package/bundles/officeimo.mjs +140 -54
  12. package/dist/csv/index.js +16 -13
  13. package/dist/integrations/canopyx/diagnostics.d.ts +3 -0
  14. package/dist/integrations/canopyx/diagnostics.js +17 -0
  15. package/dist/integrations/canopyx/grouping.d.ts +6 -0
  16. package/dist/integrations/canopyx/grouping.js +188 -0
  17. package/dist/integrations/canopyx/index.d.ts +2 -2
  18. package/dist/integrations/canopyx/index.js +72 -15
  19. package/dist/integrations/canopyx/metadata.d.ts +4 -0
  20. package/dist/integrations/canopyx/metadata.js +51 -0
  21. package/dist/integrations/canopyx/presentation.d.ts +8 -0
  22. package/dist/integrations/canopyx/presentation.js +40 -0
  23. package/dist/integrations/canopyx/rule-predicates.d.ts +3 -0
  24. package/dist/integrations/canopyx/rule-predicates.js +110 -0
  25. package/dist/integrations/canopyx/rules.d.ts +6 -0
  26. package/dist/integrations/canopyx/rules.js +176 -0
  27. package/dist/integrations/canopyx/source.js +24 -22
  28. package/dist/integrations/canopyx/types.d.ts +89 -8
  29. package/dist/integrations/canopyx/workbook.d.ts +6 -0
  30. package/dist/integrations/canopyx/workbook.js +52 -0
  31. package/dist/pdf/font-resources.js +33 -14
  32. package/dist/pdf/pages.js +60 -14
  33. package/dist/pdf/table-band-flow.js +7 -2
  34. package/dist/pdf/table-band-plan.js +9 -1
  35. package/dist/pdf/table-layout.js +6 -2
  36. package/dist/pdf/table-structure.js +9 -8
  37. package/package.json +1 -1
@@ -2333,7 +2333,8 @@ const { pdfNumber, unicodeHex } = _m19;
2333
2333
 
2334
2334
  const { checkAbort, pause, taskYieldDue } = _m3;
2335
2335
 
2336
- const standardHexBytes = Object.freeze(Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, "0")));
2336
+ const hexBytes = Object.freeze(Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, "0")));
2337
+ function cidHex(cid) { return hexBytes[cid >>> 8] + hexBytes[cid & 255]; }
2337
2338
  class PdfFontResource {
2338
2339
  index;
2339
2340
  bold;
@@ -2364,12 +2365,16 @@ class PdfFontResource {
2364
2365
  width(scalar) {
2365
2366
  if (this.shared)
2366
2367
  return this.shared.width(scalar);
2367
- const existing = this.mappings.get(scalar);
2368
- if (existing)
2369
- return existing.width;
2370
- const standard = this.standardWidths.get(scalar);
2371
- if (standard !== undefined)
2372
- return standard;
2368
+ if (this.program) {
2369
+ const existing = this.mappings.get(scalar);
2370
+ if (existing)
2371
+ return existing.width;
2372
+ }
2373
+ else {
2374
+ const standard = this.standardWidths.get(scalar);
2375
+ if (standard !== undefined)
2376
+ return standard;
2377
+ }
2373
2378
  const resolved = resolveScalar(scalar, this.program, this.bold);
2374
2379
  if (!resolved.supported) {
2375
2380
  if (resolved.code === "unpaired-surrogate")
@@ -2382,7 +2387,8 @@ class PdfFontResource {
2382
2387
  }
2383
2388
  if (this.mappings.size >= 65535)
2384
2389
  throw new OfficeIMOError("RESOURCE_LIMIT", "A PDF font supports at most 65,535 distinct Unicode scalars.");
2385
- const mapping = { cid: this.mappings.size + 1, glyph: resolved.glyph, width: resolved.width, text: String.fromCodePoint(scalar) };
2390
+ const cid = this.mappings.size + 1;
2391
+ const mapping = { cid, hex: cidHex(cid), glyph: resolved.glyph, width: resolved.width, text: String.fromCodePoint(scalar) };
2386
2392
  this.mappings.set(scalar, mapping);
2387
2393
  return mapping.width;
2388
2394
  }
@@ -2395,8 +2401,20 @@ class PdfFontResource {
2395
2401
  let hex = "";
2396
2402
  for (const char of text) {
2397
2403
  const cp = char.codePointAt(0);
2398
- this.width(cp);
2399
- hex += this.program ? this.mappings.get(cp).cid.toString(16).padStart(4, "0") : standardHexBytes[standardCode(cp)];
2404
+ if (this.program) {
2405
+ let mapping = this.mappings.get(cp);
2406
+ // Layout normally registered the scalar already; validate only a newly painted scalar.
2407
+ if (!mapping) {
2408
+ this.width(cp);
2409
+ mapping = this.mappings.get(cp);
2410
+ }
2411
+ hex += mapping.hex;
2412
+ }
2413
+ else {
2414
+ if (!this.standardWidths.has(cp))
2415
+ this.width(cp);
2416
+ hex += hexBytes[standardCode(cp)];
2417
+ }
2400
2418
  }
2401
2419
  return "<" + hex + ">";
2402
2420
  }
@@ -2411,10 +2429,11 @@ class PdfFontResource {
2411
2429
  if (!mapping) {
2412
2430
  if (this.mappings.size >= 65535)
2413
2431
  throw new OfficeIMOError("RESOURCE_LIMIT", "A PDF font supports at most 65,535 distinct CID mappings.");
2414
- mapping = { cid: this.mappings.size + 1, glyph, width: this.program.widths[glyph], text };
2432
+ const cid = this.mappings.size + 1;
2433
+ mapping = { cid, hex: cidHex(cid), glyph, width: this.program.widths[glyph], text };
2415
2434
  this.mappings.set(key, mapping);
2416
2435
  }
2417
- return "<" + mapping.cid.toString(16).padStart(4, "0") + ">";
2436
+ return "<" + mapping.hex + ">";
2418
2437
  }
2419
2438
  async write(objects, compression) {
2420
2439
  checkAbort(this.signal);
@@ -2463,7 +2482,7 @@ class PdfFontResource {
2463
2482
  const batch = mapped.slice(i, i + 100);
2464
2483
  cmap += batch.length + " beginbfchar\n";
2465
2484
  for (const [, m] of batch)
2466
- cmap += "<" + m.cid.toString(16).padStart(4, "0") + "> <" + unicodeHex(m.text) + ">\n";
2485
+ cmap += "<" + m.hex + "> <" + unicodeHex(m.text) + ">\n";
2467
2486
  cmap += "endbfchar\n";
2468
2487
  if (taskYieldDue())
2469
2488
  await pause();
@@ -2514,7 +2533,7 @@ class PdfFontResources {
2514
2533
  if (!found)
2515
2534
  this.explicitSelections.set(explicit, selections);
2516
2535
  }
2517
- const key = String(bold) + String(italic), existing = selections.get(key);
2536
+ const key = (bold ? 2 : 0) | (italic ? 1 : 0), existing = selections.get(key);
2518
2537
  if (existing)
2519
2538
  return existing;
2520
2539
  const { font, syntheticBold, syntheticItalic } = explicit ? { font: explicit, syntheticBold: bold, syntheticItalic: italic } : selectFont(this.fonts, bold, italic);
@@ -3147,6 +3166,14 @@ async function projectBandRows(rows, band, widths, settings, fonts) {
3147
3166
  for (const row of rows) {
3148
3167
  const cells = [];
3149
3168
  for (const cell of row.cells) {
3169
+ // Ordinary data and leaf headings keep their captured width and lines in every band.
3170
+ // Look up their physical position without allocating another per-row column index.
3171
+ if (cell.span === 1) {
3172
+ const first = band.columns.indexOf(cell.first);
3173
+ if (first >= 0)
3174
+ cells.push({ ...cell, source: cell.source ?? cell, first });
3175
+ continue;
3176
+ }
3150
3177
  for (let first = 0; first < band.columns.length;) {
3151
3178
  const source = band.columns[first];
3152
3179
  if (source < cell.first || source >= cell.first + cell.span) {
@@ -3157,7 +3184,7 @@ async function projectBandRows(rows, band, widths, settings, fonts) {
3157
3184
  while (end < band.columns.length && band.columns[end] === band.columns[end - 1] + 1 && band.columns[end] < cell.first + cell.span)
3158
3185
  end++;
3159
3186
  const width = band.columns.slice(first, end).reduce((sum, index) => sum + widths[index], 0);
3160
- const lines = cell.span === 1 ? cell.lines : await wrapPdfText(cell.captured, fonts, settings.fontSize, width - settings.padding * 2, settings, cell.style.wrapText !== false);
3187
+ const lines = await wrapPdfText(cell.captured, fonts, settings.fontSize, width - settings.padding * 2, settings, cell.style.wrapText !== false);
3161
3188
  cells.push({ ...cell, source: cell.source ?? cell, first, span: end - first, width, lines,
3162
3189
  lineHeight: lines.reduce((height, line) => Math.max(height, line.lineHeight), cell.font.lineHeight(settings.fontSize)) });
3163
3190
  first = end;
@@ -3309,8 +3336,12 @@ class PdfTableLayout {
3309
3336
  lines };
3310
3337
  }
3311
3338
  row(cells) {
3312
- const lines = Math.max(1, ...cells.map(c => c.lines.length));
3313
- const lineHeight = Math.max(this.lineHeight, ...cells.map(c => c.lineHeight));
3339
+ let lines = 1, lineHeight = this.lineHeight;
3340
+ for (let index = 0; index < cells.length; index++) {
3341
+ const cell = cells[index];
3342
+ lines = Math.max(lines, cell.lines.length);
3343
+ lineHeight = Math.max(lineHeight, cell.lineHeight);
3344
+ }
3314
3345
  return { cells, lines, lineHeight, height: lines * lineHeight + this.settings.padding * 2 };
3315
3346
  }
3316
3347
  async headers() {
@@ -3463,7 +3494,7 @@ class PdfTableBandFlow {
3463
3494
  await this.flush();
3464
3495
  }
3465
3496
  async row(row, allowFirstFragment = false) {
3466
- const { padding, fontSize, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = this.layout.minimumRowHeight(row);
3497
+ const { padding, fontSize, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = minimumLines * row.lineHeight + padding * 2;
3467
3498
  if (minimumHeight > this.painter.firstFullCapacity + .001 || minimumHeight > this.painter.continuationCapacity + .001)
3468
3499
  throw new RangeError("Repeated PDF identifiers must fit intact below the first and continued band headings/context.");
3469
3500
  // Keep ordinary rows intact when they fit fresh. A kept heading/caption can deliberately
@@ -3497,9 +3528,14 @@ class PdfTableBandFlow {
3497
3528
  let remaining = false;
3498
3529
  const cells = rows[0].cells.map(cell => {
3499
3530
  const source = this.layout.bands[index].columns[cell.first];
3500
- const repeated = this.layout.repeatedColumn(source), visible = repeated ? cell.lines : cell.lines.slice(first, first + lines);
3531
+ const repeated = this.layout.repeatedColumn(source), reusable = cell.span === 1 && (cell.source?.span ?? 1) === 1 && (cell.rowSpan ?? 1) === 1 &&
3532
+ cell.height === undefined && first === 0 && (repeated || lines >= cell.lines.length);
3533
+ const visible = repeated || reusable ? cell.lines : cell.lines.slice(first, first + lines);
3501
3534
  if (!repeated && (visible.length > 0 || cell.link !== undefined))
3502
3535
  remaining = true;
3536
+ // A complete first fragment already owns these lines and their maximum font metrics.
3537
+ if (reusable)
3538
+ return cell;
3503
3539
  const { height: _height, ...plain } = cell;
3504
3540
  return { ...plain, lines: visible,
3505
3541
  lineHeight: visible.reduce((value, line) => Math.max(value, line.lineHeight), cell.font.lineHeight(fontSize)),
@@ -3607,30 +3643,31 @@ class PdfTableStructure {
3607
3643
  return row.cells.map(cell => this.cells.get(cell));
3608
3644
  const rowId = this.structure.element("TR", parent);
3609
3645
  this.rows.set(row, rowId);
3610
- const headers = row.cells.map((cell, index) => rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex);
3611
3646
  // Allocate in source order, then resolve every row header before associating even earlier data cells.
3612
3647
  // Generated summary labels override detail roles so numeric subtotal cells never become row headers.
3613
3648
  const ids = row.cells.map((cell, index) => {
3614
- const id = this.structure.element(headers[index] ? "TH" : "TD", rowId);
3649
+ const header = rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex;
3650
+ const id = this.structure.element(header ? "TH" : "TD", rowId);
3615
3651
  this.cells.set(cell, id);
3616
3652
  return id;
3617
3653
  });
3618
- const rowHeaders = [];
3654
+ let rowHeaders;
3619
3655
  for (let index = 0; index < ids.length; index++)
3620
- if (headers[index])
3621
- rowHeaders.push(await this.structure.identifier(ids[index]));
3656
+ if (rowHeaderIndex === undefined ? row.cells[index].rowHeader === true : index === rowHeaderIndex)
3657
+ (rowHeaders ??= []).push(await this.structure.identifier(ids[index]));
3622
3658
  for (let index = 0; index < row.cells.length; index++) {
3623
3659
  const cell = row.cells[index];
3624
- if (!rowHeaders.length && cell.span === 1 && (cell.rowSpan ?? 1) === 1) {
3660
+ if (!rowHeaders && cell.span === 1 && (cell.rowSpan ?? 1) === 1) {
3625
3661
  const attributes = this.ordinaryAttributes[cell.first] ??=
3626
3662
  await this.structure.attributeReference(this.attributeDictionary(cell, this.associations(cell)));
3627
3663
  this.structure.setAttributes(ids[index], attributes);
3628
3664
  continue;
3629
3665
  }
3630
3666
  const associations = this.associations(cell);
3631
- if (!headers[index])
3667
+ const header = rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex;
3668
+ if (!header && rowHeaders)
3632
3669
  associations.push(...rowHeaders);
3633
- this.structure.setAttributes(ids[index], this.attributes(cell, associations, headers[index] ? "Row" : undefined));
3670
+ this.structure.setAttributes(ids[index], this.attributes(cell, associations, header ? "Row" : undefined));
3634
3671
  }
3635
3672
  return ids;
3636
3673
  }
@@ -3814,7 +3851,8 @@ class PdfPages {
3814
3851
  outlines;
3815
3852
  references = [];
3816
3853
  current = 0;
3817
- commands = [];
3854
+ commands = "";
3855
+ commandParts = [];
3818
3856
  commandBytes = 0;
3819
3857
  annotations = [];
3820
3858
  hyperlinks = 0;
@@ -3832,6 +3870,12 @@ class PdfPages {
3832
3870
  pendingBookmarks = [];
3833
3871
  pageNumberWidth = 0;
3834
3872
  colors = new Map();
3873
+ textFont;
3874
+ textSize = 0;
3875
+ textColor = "";
3876
+ textPrefix = "";
3877
+ rectangleLefts;
3878
+ rectangleColumns = [];
3835
3879
  externalObjects = new Map();
3836
3880
  bandFlow;
3837
3881
  bandCellBudget = false;
@@ -3898,7 +3942,7 @@ class PdfPages {
3898
3942
  }
3899
3943
  add(command) {
3900
3944
  this.retainPageBytes(command.length);
3901
- this.commands.push(command);
3945
+ this.commands += command;
3902
3946
  }
3903
3947
  retainPageBytes(length) {
3904
3948
  this.commandBytes += length;
@@ -3918,9 +3962,17 @@ class PdfPages {
3918
3962
  return this.structure ? "/Artifact << /Type /" + type + " >> BDC\n" + command + "EMC\n" : command;
3919
3963
  }
3920
3964
  text(text, font, size, x, baseline, foreground = "111827", element) {
3921
- const n = pdfNumber, shear = font.syntheticItalic ? .213 : 0;
3922
- const command = "q " + this.rgb(foreground) + " rg " + this.rgb(foreground) + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
3923
- (font.syntheticBold ? n(size * .025) + " w 2 Tr " : "0 Tr ") + "1 0 " + n(shear) + " 1 " + n(x) + " " + n(baseline) + " Tm " + font.encode(text) + " Tj ET Q\n";
3965
+ const n = pdfNumber;
3966
+ if (font !== this.textFont || size !== this.textSize || foreground !== this.textColor) {
3967
+ const shear = font.syntheticItalic ? .213 : 0, rgb = this.rgb(foreground);
3968
+ // Keep one prefix, independent of report size. Resource identity includes synthetic styling.
3969
+ this.textPrefix = "q " + rgb + " rg " + rgb + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
3970
+ (font.syntheticBold ? n(size * .025) + " w 2 Tr " : "0 Tr ") + "1 0 " + n(shear) + " 1 ";
3971
+ this.textFont = font;
3972
+ this.textSize = size;
3973
+ this.textColor = foreground;
3974
+ }
3975
+ const command = this.textPrefix + n(x) + " " + n(baseline) + " Tm " + font.encode(text) + " Tj ET Q\n";
3924
3976
  this.add(this.structure && element !== undefined ? this.structure.mark(element) + command + "EMC\n" : this.artifact(command, "Pagination"));
3925
3977
  }
3926
3978
  link(link, x, bottom, width, height, element) {
@@ -3950,8 +4002,8 @@ class PdfPages {
3950
4002
  for (const segment of line.segments) {
3951
4003
  const registered = marks?.get(segment), owner = registered?.owner ?? (segment.link && this.structure && element !== undefined ? this.structure.link(element, segment.link) : element);
3952
4004
  if (segment.glyphs) {
3953
- const font = segment.font, n = pdfNumber, shear = font.syntheticItalic ? .213 : 0;
3954
- let cursor = x, command = "q " + this.rgb(segment.color ?? "111827") + " rg " + this.rgb(segment.color ?? "111827") + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
4005
+ const font = segment.font, n = pdfNumber, shear = font.syntheticItalic ? .213 : 0, rgb = this.rgb(segment.color ?? "111827");
4006
+ let cursor = x, command = "q " + rgb + " rg " + rgb + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
3955
4007
  (font.syntheticBold ? n(size * .025) + " w 2 Tr " : "0 Tr ");
3956
4008
  for (const glyph of segment.glyphs) {
3957
4009
  command += "1 0 " + n(shear) + " 1 " + n(cursor + (glyph.xOffset + shear * glyph.yOffset) * size / 1000) + " " + n(baseline + glyph.yOffset * size / 1000) + " Tm " + font.encodeGlyph(glyph.id, glyph.logicalText) + " Tj\n";
@@ -3999,7 +4051,8 @@ class PdfPages {
3999
4051
  this.current = this.objects.reserve();
4000
4052
  this.references.push(this.current);
4001
4053
  }
4002
- this.commands = [];
4054
+ this.commands = "";
4055
+ this.commandParts = [];
4003
4056
  this.annotations = [];
4004
4057
  this.commandBytes = 0;
4005
4058
  this.bodyAdded = false;
@@ -4082,15 +4135,32 @@ class PdfPages {
4082
4135
  if (!this.layout)
4083
4136
  throw new Error("A table layout is required before drawing rows.");
4084
4137
  this.bodyAdded = true;
4085
- const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2;
4138
+ const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2, lefts = this.layout.lefts;
4139
+ // One geometry token per active physical column; table/band changes release the old tokens.
4140
+ if (this.rectangleLefts !== lefts) {
4141
+ this.rectangleLefts = lefts;
4142
+ this.rectangleColumns = [];
4143
+ }
4144
+ let rectangleHeight, rectangleBottom = "", rectangleHeightText = "";
4086
4145
  for (const [index, cell] of row.cells.entries()) {
4087
4146
  if (this.bandCellBudget)
4088
4147
  this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" :
4089
4148
  (cell.height === undefined ? cell.lines.slice(firstLine, firstLine + lineCount) : cell.lines).map(line => line.text).join(""));
4090
- const x = this.layout.lefts[cell.first], cellHeight = cell.height ?? height;
4149
+ const x = lefts[cell.first], cellHeight = cell.height ?? height;
4150
+ if (cellHeight !== rectangleHeight) {
4151
+ rectangleBottom = n(this.y - cellHeight);
4152
+ rectangleHeightText = n(cellHeight);
4153
+ rectangleHeight = cellHeight;
4154
+ }
4155
+ let horizontal = this.rectangleColumns[cell.first];
4156
+ if (!horizontal || horizontal.x !== x || horizontal.width !== cell.width) {
4157
+ horizontal = { x, width: cell.width, left: n(x), widthText: n(cell.width) };
4158
+ this.rectangleColumns[cell.first] = horizontal;
4159
+ }
4160
+ const rectangle = horizontal.left + " " + rectangleBottom + " " + horizontal.widthText + " " + rectangleHeightText;
4091
4161
  if (cell.style.background)
4092
- this.add(this.artifact("q " + this.rgb(cell.style.background) + " rg " + n(x) + " " + n(this.y - cellHeight) + " " + n(cell.width) + " " + n(cellHeight) + " re f Q\n"));
4093
- this.add(this.artifact("q 0.82 0.85 0.89 RG 0.4 w " + n(x) + " " + n(this.y - cellHeight) + " " + n(cell.width) + " " + n(cellHeight) + " re S Q\n"));
4162
+ this.add(this.artifact("q " + this.rgb(cell.style.background) + " rg " + rectangle + " re f Q\n"));
4163
+ this.add(this.artifact("q 0.82 0.85 0.89 RG 0.4 w " + rectangle + " re S Q\n"));
4094
4164
  const element = elements?.[index], artifact = cell.semanticArtifact || repeated[index], owner = cell.link && this.structure && element !== undefined ? this.structure.link(element, cell.link) : element;
4095
4165
  for (let line = firstLine; line < Math.min(cell.lines.length, cell.height ? cell.lines.length : firstLine + lineCount); line++) {
4096
4166
  const text = cell.lines[line], left = cell.style.alignment === "right" ? cell.width - padding - text.width : cell.style.alignment === "center" ? (cell.width - text.width) / 2 : padding;
@@ -4100,6 +4170,7 @@ class PdfPages {
4100
4170
  this.link(cell.link, x, this.y - cellHeight, cell.width, cellHeight, owner);
4101
4171
  }
4102
4172
  this.y -= row.structured ? row.height : height;
4173
+ this.sealCommands();
4103
4174
  }
4104
4175
  async block(rows) {
4105
4176
  if (this.bandFlow)
@@ -4425,9 +4496,22 @@ class PdfPages {
4425
4496
  marker: { line: item.marker, gap: item.markerGap, ...(label === undefined ? {} : { owner: label }) } });
4426
4497
  await this.structure?.complete(li);
4427
4498
  }
4499
+ sealCommands() {
4500
+ if (this.commands) {
4501
+ this.commandParts.push(this.commands);
4502
+ this.commands = "";
4503
+ }
4504
+ }
4505
+ takeCommands() {
4506
+ this.sealCommands();
4507
+ const content = this.commandParts.join("");
4508
+ // Encoding and awaited delivery own the page value; the next page starts independently.
4509
+ this.commandParts = [];
4510
+ return content;
4511
+ }
4428
4512
  async finishPage() {
4429
4513
  const contents = this.objects.reserve(), { page, options } = this.settings;
4430
- await this.objects.stream(contents, this.commands.join(""), "", options.compression !== false);
4514
+ await this.objects.stream(contents, this.takeCommands(), "", options.compression !== false);
4431
4515
  const annotations = [];
4432
4516
  for (const annotation of this.annotations) {
4433
4517
  annotations.push(annotation.id);
@@ -4439,7 +4523,6 @@ class PdfPages {
4439
4523
  (annotations.length ? " /Annots [" + annotations.map(id => id + " 0 R").join(" ") + "]" : "") + " >>");
4440
4524
  if (this.structure)
4441
4525
  await this.structure.finishPage();
4442
- this.commands = [];
4443
4526
  this.annotations = [];
4444
4527
  this.commandBytes = 0;
4445
4528
  this.current = 0;