Skip to content

Commit 3cf5b58

Browse files
authored
chore(pdf-server): switch pdf-lib to maintained @cantoo/pdf-lib fork (#651)
The original pdf-lib package has been unmaintained since Nov 2021. @cantoo/pdf-lib is an actively maintained, API-compatible fork with ongoing releases and accumulated bugfixes. Also updates test assertions from the deprecated PDFNumber.value() to PDFNumber.asNumber() per the fork's API guidance.
1 parent 0008d3b commit 3cf5b58

6 files changed

Lines changed: 94 additions & 37 deletions

File tree

examples/pdf-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
"build:mcpb": "npm run build && node build-mcpb.mjs"
2626
},
2727
"dependencies": {
28+
"@cantoo/pdf-lib": "^2.6.5",
2829
"@modelcontextprotocol/ext-apps": "^1.0.0",
2930
"@modelcontextprotocol/sdk": "^1.29.0",
3031
"cors": "^2.8.5",
3132
"express": "^5.1.0",
32-
"pdf-lib": "^1.17.1",
3333
"pdfjs-dist": "^5.0.0",
3434
"zod": "^4.1.13"
3535
},

examples/pdf-server/server.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import path from "node:path";
55
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
66
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
77
import { getDocument } from "pdfjs-dist/legacy/build/pdf.mjs";
8-
import { PDFDocument } from "pdf-lib";
8+
import { PDFDocument } from "@cantoo/pdf-lib";
99
import { makeRandomJpeg } from "../../tests/helpers/range-counting-server";
1010
import {
1111
createPdfCache,

examples/pdf-server/src/pdf-annotations.test.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ import {
1818
type PdfAnnotationDef,
1919
type AnnotationDiff,
2020
} from "./pdf-annotations";
21-
import { PDFDocument, PDFDict, PDFName, PDFArray, PDFNumber } from "pdf-lib";
21+
import {
22+
PDFDocument,
23+
PDFDict,
24+
PDFName,
25+
PDFArray,
26+
PDFNumber,
27+
} from "@cantoo/pdf-lib";
2228

2329
// =============================================================================
2430
// Diff Model
@@ -1074,16 +1080,16 @@ describe("buildAnnotatedPdfBytes", () => {
10741080
// Check /C (stroke color) = [1, 0, 0] for #ff0000
10751081
const cArr = annotDict.get(PDFName.of("C")) as PDFArray;
10761082
expect(cArr).toBeDefined();
1077-
expect((cArr.get(0) as PDFNumber).value()).toBe(1); // r
1078-
expect((cArr.get(1) as PDFNumber).value()).toBe(0); // g
1079-
expect((cArr.get(2) as PDFNumber).value()).toBe(0); // b
1083+
expect((cArr.get(0) as PDFNumber).asNumber()).toBe(1); // r
1084+
expect((cArr.get(1) as PDFNumber).asNumber()).toBe(0); // g
1085+
expect((cArr.get(2) as PDFNumber).asNumber()).toBe(0); // b
10801086

10811087
// Check /IC (fill color) = [0, 1, 0] for #00ff00
10821088
const icArr = annotDict.get(PDFName.of("IC")) as PDFArray;
10831089
expect(icArr).toBeDefined();
1084-
expect((icArr.get(0) as PDFNumber).value()).toBe(0); // r
1085-
expect((icArr.get(1) as PDFNumber).value()).toBe(1); // g
1086-
expect((icArr.get(2) as PDFNumber).value()).toBe(0); // b
1090+
expect((icArr.get(0) as PDFNumber).asNumber()).toBe(0); // r
1091+
expect((icArr.get(1) as PDFNumber).asNumber()).toBe(1); // g
1092+
expect((icArr.get(2) as PDFNumber).asNumber()).toBe(0); // b
10871093
});
10881094

10891095
it("adds freetext annotation to PDF", async () => {
@@ -1159,9 +1165,9 @@ describe("buildAnnotatedPdfBytes", () => {
11591165
// Check /C color
11601166
const cArr = annotDict.get(PDFName.of("C")) as PDFArray;
11611167
expect(cArr).toBeDefined();
1162-
expect((cArr.get(0) as PDFNumber).value()).toBe(0);
1163-
expect((cArr.get(1) as PDFNumber).value()).toBe(1);
1164-
expect((cArr.get(2) as PDFNumber).value()).toBe(0);
1168+
expect((cArr.get(0) as PDFNumber).asNumber()).toBe(0);
1169+
expect((cArr.get(1) as PDFNumber).asNumber()).toBe(1);
1170+
expect((cArr.get(2) as PDFNumber).asNumber()).toBe(0);
11651171

11661172
// Check appearance stream exists and contains the color
11671173
const ap = annotDict.get(PDFName.of("AP")) as PDFDict;

examples/pdf-server/src/pdf-annotations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
PDFOptionList,
2525
PDFRadioGroup,
2626
type PDFForm,
27-
} from "pdf-lib";
27+
} from "@cantoo/pdf-lib";
2828

2929
// =============================================================================
3030
// Types

package-lock.json

Lines changed: 69 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/helpers/range-counting-server.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
*/
99
import http from "node:http";
1010
import type { AddressInfo } from "node:net";
11-
import { PDFDocument, PDFName, PDFString, StandardFonts } from "pdf-lib";
11+
import {
12+
PDFDocument,
13+
PDFName,
14+
PDFString,
15+
StandardFonts,
16+
} from "@cantoo/pdf-lib";
1217

1318
export interface RangeServerStats {
1419
/** Total bytes written across all responses (sum of slice lengths). */

0 commit comments

Comments
 (0)