From b6c829c37200212742623e83258a2e7ab1346d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Hillerstr=C3=B6m?= Date: Tue, 2 Sep 2025 10:05:39 +0200 Subject: [PATCH 1/4] Add rgb support to spot colors --- lib/spotcolor.js | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/lib/spotcolor.js b/lib/spotcolor.js index 1bbdd054..1a498401 100644 --- a/lib/spotcolor.js +++ b/lib/spotcolor.js @@ -1,22 +1,37 @@ export default class SpotColor { constructor(doc, name, C, M, Y, K) { - this.id = 'CS' + Object.keys(doc.spotColors).length; - this.name = name; - this.values = [C, M, Y, K]; - this.ref = doc.ref([ - 'Separation', - this.name, - 'DeviceCMYK', - { - Range: [0, 1, 0, 1, 0, 1, 0, 1], - C0: [0, 0, 0, 0], - C1: this.values.map((value) => value / 100), + if (typeof K === "undefined") { + this.id = 'CS' + Object.keys(doc.spotColors).length; + this.name = name; + this.values = [C, M, Y]; + this.ref = doc.ref(['Separation', this.name, 'DeviceRGB', { + Range: [0, 1, 0, 1, 0, 1], + C0: [0, 0, 0], + C1: this.values.map(value => value / 255), FunctionType: 2, Domain: [0, 1], - N: 1, - }, - ]); - this.ref.end(); + N: 1 + }]); + this.ref.end(); + } else { + this.id = 'CS' + Object.keys(doc.spotColors).length; + this.name = name; + this.values = [C, M, Y, K]; + this.ref = doc.ref([ + 'Separation', + this.name, + 'DeviceCMYK', + { + Range: [0, 1, 0, 1, 0, 1, 0, 1], + C0: [0, 0, 0, 0], + C1: this.values.map((value) => value / 100), + FunctionType: 2, + Domain: [0, 1], + N: 1, + }, + ]); + this.ref.end(); + } } toString() { From deebf4ec4dff60da6016c9ecfbdcce964ec6f397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Hillerstr=C3=B6m?= Date: Tue, 2 Sep 2025 10:34:07 +0200 Subject: [PATCH 2/4] Add unit test --- tests/unit/color.spec.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/unit/color.spec.js b/tests/unit/color.spec.js index 0b482205..2fbc021a 100644 --- a/tests/unit/color.spec.js +++ b/tests/unit/color.spec.js @@ -56,4 +56,25 @@ describe('color', function () { '>>', ]); }); + + test('spot color with rgb', function () { + const doc = new PDFDocument(); + const data = logData(doc); + doc.addSpotColor('MAGENTA', 255, 0, 255); + doc.fillColor('MAGENTA').text('This text uses spot color!'); + doc.end(); + + expect(data).toContainChunk([ + `6 0 obj`, + '<<\n' + + '/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n' + + '/ColorSpace <<\n' + + '/CS0 8 0 R\n' + + '>>\n' + + '/Font <<\n' + + '/F1 9 0 R\n' + + '>>\n' + + '>>', + ]); + }); }); From 3552eaea06ce3dd5ec214819baa12ecfc0f7a230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Hillerstr=C3=B6m?= Date: Tue, 2 Sep 2025 10:37:46 +0200 Subject: [PATCH 3/4] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0c64641..0dbc0c8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Unreleased +-- Add support for rgb values in a spot color + ### [v0.17.1] - 2025-05-02 - Fix null values in table cells rendering as `[object Object]` From d4367113bb8fd17cb5f31f860ee1edcde404480a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Hillerstr=C3=B6m?= Date: Wed, 5 Nov 2025 12:12:48 +0100 Subject: [PATCH 4/4] Run prettier --- lib/spotcolor.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/spotcolor.js b/lib/spotcolor.js index 1a498401..93aa8679 100644 --- a/lib/spotcolor.js +++ b/lib/spotcolor.js @@ -1,17 +1,22 @@ export default class SpotColor { constructor(doc, name, C, M, Y, K) { - if (typeof K === "undefined") { + if (typeof K === 'undefined') { this.id = 'CS' + Object.keys(doc.spotColors).length; this.name = name; this.values = [C, M, Y]; - this.ref = doc.ref(['Separation', this.name, 'DeviceRGB', { - Range: [0, 1, 0, 1, 0, 1], - C0: [0, 0, 0], - C1: this.values.map(value => value / 255), - FunctionType: 2, - Domain: [0, 1], - N: 1 - }]); + this.ref = doc.ref([ + 'Separation', + this.name, + 'DeviceRGB', + { + Range: [0, 1, 0, 1, 0, 1], + C0: [0, 0, 0], + C1: this.values.map((value) => value / 255), + FunctionType: 2, + Domain: [0, 1], + N: 1, + }, + ]); this.ref.end(); } else { this.id = 'CS' + Object.keys(doc.spotColors).length;