pdf-lite 1.7.4-alpha.2 → 1.7.4-alpha.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.
@@ -26,6 +26,11 @@ export class PdfGraphics {
26
26
  }
27
27
  beginText() {
28
28
  this.lines.push('BT');
29
+ // Re-emit font inside text object — some viewers (e.g. pdfjs)
30
+ // require Tf inside BT..ET before any text rendering operator.
31
+ if (this.defaultAppearance) {
32
+ this.lines.push(this.defaultAppearance.toString());
33
+ }
29
34
  return this;
30
35
  }
31
36
  endText() {
@@ -1,4 +1,5 @@
1
1
  import { PdfString } from '../../core/objects/pdf-string.js';
2
+ import { PdfName } from '../../core/objects/pdf-name.js';
2
3
  import { encodeToPDFDocEncoding } from '../../utils/encodeToPDFDocEncoding.js';
3
4
  /**
4
5
  * Value object that parses and builds DA (Default Appearance) strings.
@@ -12,7 +13,7 @@ export class PdfDefaultAppearance extends PdfString {
12
13
  _fontSize;
13
14
  _colorOp;
14
15
  constructor(fontName, fontSize, colorOp) {
15
- super(`/${fontName} ${fontSize} Tf ${colorOp}`);
16
+ super(`/${PdfName.escapeName(fontName)} ${fontSize} Tf ${colorOp}`);
16
17
  this._fontName = fontName;
17
18
  this._fontSize = fontSize;
18
19
  this._colorOp = colorOp;
@@ -43,13 +44,13 @@ export class PdfDefaultAppearance extends PdfString {
43
44
  this.raw = encodeToPDFDocEncoding(this.toString());
44
45
  }
45
46
  toString() {
46
- return `/${this._fontName} ${this._fontSize} Tf ${this._colorOp}`;
47
+ return `/${PdfName.escapeName(this._fontName)} ${this._fontSize} Tf ${this._colorOp}`;
47
48
  }
48
49
  static parse(da) {
49
50
  const fontMatch = da.match(/\/([\S]+)\s+([\d.]+)\s+Tf/);
50
51
  if (!fontMatch)
51
52
  return null;
52
- const fontName = fontMatch[1];
53
+ const fontName = PdfName.unescapeName(fontMatch[1]);
53
54
  const fontSize = parseFloat(fontMatch[2]) || 0;
54
55
  let colorOp = '0 g';
55
56
  const rgMatch = da.match(/([\d.]+\s+[\d.]+\s+[\d.]+)\s+rg/);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdf-lite",
3
- "version": "1.7.4-alpha.2",
3
+ "version": "1.7.4-alpha.3",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "exports": {