@libpdf/core 0.2.0 → 0.2.2
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 +1 -1
- package/dist/index.mjs +36 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A modern PDF library for TypeScript. Parse, modify, and generate PDFs with a clean, intuitive API.
|
|
4
4
|
|
|
5
|
-
> **Beta Software**: LibPDF is under active development
|
|
5
|
+
> **Beta Software**: LibPDF is under active development and APIs may change between minor versions, but we use it in production at [Documenso](https://documenso.com) and consider it ready for real-world use.
|
|
6
6
|
|
|
7
7
|
## Why LibPDF?
|
|
8
8
|
|
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { createCMSECDSASignature } from "pkijs";
|
|
|
9
9
|
import { base64 } from "@scure/base";
|
|
10
10
|
|
|
11
11
|
//#region package.json
|
|
12
|
-
var version = "0.2.
|
|
12
|
+
var version = "0.2.2";
|
|
13
13
|
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/objects/pdf-array.ts
|
|
@@ -23904,7 +23904,7 @@ var PathBuilder = class {
|
|
|
23904
23904
|
dashArray: options.dashArray,
|
|
23905
23905
|
dashPhase: options.dashPhase,
|
|
23906
23906
|
windingRule: options.windingRule,
|
|
23907
|
-
graphicsStateName: gsName
|
|
23907
|
+
graphicsStateName: gsName ? `/${gsName}` : void 0
|
|
23908
23908
|
});
|
|
23909
23909
|
this.emitOps(ops);
|
|
23910
23910
|
}
|
|
@@ -24499,7 +24499,7 @@ var PDFPage = class PDFPage {
|
|
|
24499
24499
|
dashArray: options.borderDashArray,
|
|
24500
24500
|
dashPhase: options.borderDashPhase,
|
|
24501
24501
|
cornerRadius: options.cornerRadius,
|
|
24502
|
-
graphicsStateName: gsName
|
|
24502
|
+
graphicsStateName: gsName ? `/${gsName}` : void 0,
|
|
24503
24503
|
rotate
|
|
24504
24504
|
});
|
|
24505
24505
|
this.appendOperators(ops);
|
|
@@ -24538,7 +24538,7 @@ var PDFPage = class PDFPage {
|
|
|
24538
24538
|
dashArray: options.dashArray,
|
|
24539
24539
|
dashPhase: options.dashPhase,
|
|
24540
24540
|
lineCap: options.lineCap,
|
|
24541
|
-
graphicsStateName: gsName
|
|
24541
|
+
graphicsStateName: gsName ? `/${gsName}` : void 0
|
|
24542
24542
|
});
|
|
24543
24543
|
this.appendOperators(ops);
|
|
24544
24544
|
}
|
|
@@ -24566,7 +24566,7 @@ var PDFPage = class PDFPage {
|
|
|
24566
24566
|
fillColor: options.color,
|
|
24567
24567
|
strokeColor: options.borderColor,
|
|
24568
24568
|
strokeWidth: options.borderWidth,
|
|
24569
|
-
graphicsStateName: gsName
|
|
24569
|
+
graphicsStateName: gsName ? `/${gsName}` : void 0
|
|
24570
24570
|
});
|
|
24571
24571
|
this.appendOperators(ops);
|
|
24572
24572
|
}
|
|
@@ -24613,7 +24613,7 @@ var PDFPage = class PDFPage {
|
|
|
24613
24613
|
fillColor: options.color,
|
|
24614
24614
|
strokeColor: options.borderColor,
|
|
24615
24615
|
strokeWidth: options.borderWidth,
|
|
24616
|
-
graphicsStateName: gsName
|
|
24616
|
+
graphicsStateName: gsName ? `/${gsName}` : void 0,
|
|
24617
24617
|
rotate
|
|
24618
24618
|
});
|
|
24619
24619
|
this.appendOperators(ops);
|
|
@@ -24670,7 +24670,7 @@ var PDFPage = class PDFPage {
|
|
|
24670
24670
|
width: measureText(line, font, fontSize)
|
|
24671
24671
|
}));
|
|
24672
24672
|
const ops = [pushGraphicsState()];
|
|
24673
|
-
if (gsName) ops.push(setGraphicsState(gsName));
|
|
24673
|
+
if (gsName) ops.push(setGraphicsState(`/${gsName}`));
|
|
24674
24674
|
if (options.rotate) {
|
|
24675
24675
|
const textWidth = options.maxWidth ?? Math.max(...lines.map((l) => l.width));
|
|
24676
24676
|
let ascent;
|
|
@@ -25447,8 +25447,8 @@ var PDFPage = class PDFPage {
|
|
|
25447
25447
|
registerGraphicsStateForOpacity(fillOpacity, strokeOpacity) {
|
|
25448
25448
|
if (fillOpacity === void 0 && strokeOpacity === void 0) return null;
|
|
25449
25449
|
const params = {};
|
|
25450
|
-
if (fillOpacity !== void 0) params.
|
|
25451
|
-
if (strokeOpacity !== void 0) params.
|
|
25450
|
+
if (fillOpacity !== void 0) params.ca = Math.max(0, Math.min(1, fillOpacity));
|
|
25451
|
+
if (strokeOpacity !== void 0) params.CA = Math.max(0, Math.min(1, strokeOpacity));
|
|
25452
25452
|
return this.addGraphicsState(params);
|
|
25453
25453
|
}
|
|
25454
25454
|
/**
|
|
@@ -30610,22 +30610,36 @@ var DocumentParser = class {
|
|
|
30610
30610
|
else throw error;
|
|
30611
30611
|
}
|
|
30612
30612
|
const lengthResolver = (ref) => {
|
|
30613
|
-
const
|
|
30614
|
-
const cached = cache.get(
|
|
30615
|
-
if (cached
|
|
30613
|
+
const cacheKey = `${ref.objectNumber} ${ref.generation}`;
|
|
30614
|
+
const cached = cache.get(cacheKey);
|
|
30615
|
+
if (cached instanceof PdfNumber) return cached.value;
|
|
30616
30616
|
const entry = xref.get(ref.objectNumber);
|
|
30617
|
-
if (entry
|
|
30618
|
-
|
|
30619
|
-
|
|
30620
|
-
|
|
30621
|
-
|
|
30622
|
-
|
|
30623
|
-
|
|
30624
|
-
|
|
30617
|
+
if (!entry || entry.type === "free") return null;
|
|
30618
|
+
const savedPosition = this.scanner.position;
|
|
30619
|
+
try {
|
|
30620
|
+
let lengthObj = null;
|
|
30621
|
+
if (entry.type === "uncompressed") lengthObj = new IndirectObjectParser(this.scanner).parseObjectAt(entry.offset).value;
|
|
30622
|
+
else {
|
|
30623
|
+
const streamEntry = xref.get(entry.streamObjNum);
|
|
30624
|
+
if (streamEntry?.type === "uncompressed") {
|
|
30625
|
+
let objStreamParser = objectStreamCache.get(entry.streamObjNum);
|
|
30626
|
+
if (!objStreamParser) {
|
|
30627
|
+
const streamResult = new IndirectObjectParser(this.scanner).parseObjectAt(streamEntry.offset);
|
|
30628
|
+
if (streamResult.value instanceof PdfStream) {
|
|
30629
|
+
objStreamParser = new ObjectStreamParser(streamResult.value);
|
|
30630
|
+
objectStreamCache.set(entry.streamObjNum, objStreamParser);
|
|
30631
|
+
}
|
|
30632
|
+
}
|
|
30633
|
+
if (objStreamParser) lengthObj = objStreamParser.getObject(entry.indexInStream);
|
|
30625
30634
|
}
|
|
30626
|
-
} catch {
|
|
30627
|
-
this.scanner.moveTo(savedPosition);
|
|
30628
30635
|
}
|
|
30636
|
+
this.scanner.moveTo(savedPosition);
|
|
30637
|
+
if (lengthObj instanceof PdfNumber) {
|
|
30638
|
+
cache.set(cacheKey, lengthObj);
|
|
30639
|
+
return lengthObj.value;
|
|
30640
|
+
}
|
|
30641
|
+
} catch {
|
|
30642
|
+
this.scanner.moveTo(savedPosition);
|
|
30629
30643
|
}
|
|
30630
30644
|
return null;
|
|
30631
30645
|
};
|