Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]`
Expand Down
45 changes: 30 additions & 15 deletions lib/spotcolor.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/color.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' +
'>>',
]);
});
});
Loading