pdf-lib
pdf-lib copied to clipboard
Add support for Separation colors
What?
This PR adds support for separation colors in PDF-LIB, and answers the following issue request: Hopding/pdf-lib#444
Code sample:
const pdfSeparation = await pdfDoc.embedSeparation(
'PANTONE 123 C',
cmyk(0, 0.22, 0.83, 0),
);
const color = page.getSeparationColor(pdfSeparation, 0.5);
page.drawText('This text will be printed using a spot color', { color });
Why?
Spot colors are used in professional printing, to add colors or effects that cannot be reproduced with traditional CMYK processes. For example:
- Pantone inks
- White-on-black printing
- Metallic or fluorescent inks
- Varnish layers
How?
The PDF specification, section 8.6.6.4, specifies how to embed and use Separation color spaces. This PR consists in 3 parts:
- Define a new object type,
PDFSeparation
, that can be embedded in the document, and add a method inPDFDocument
that allows for embedding said object. - Define a method in
PDFPage
that allows to reference a previously-embeddedPDFSeparation
into the page's resources (Resource of type ColorSpace, see section 7.8.3). Such method returns a new type of Color, which can be used only in the given page. - In each Page method that accept a Color parameter, add support for Separation colors (switch color space using the
cs
andCS
operators prior to setting the ting)
Testing?
Unit tests were for the new methods.
This PR was tested by generating a new PDF and editing an old PDF to add a text using a Separation color.
In Adobe Pro, the Separation layer is clearly visible in Output Preview as a distinct layer, and is also displayed on screen using its alternate color.
The generated PDFs are displayed property in Chrome, Firefox, Adobe PDF Pro and Foxit Reader.
The integration test suites for node, deno, browser were run and no visual issue was found.
New Dependencies?
No new dependencies.
Screenshots

Suggested Reading?
Yes
Anything Else?
No
Checklist
- [x] I read CONTRIBUTING.md.
- [x] I read MAINTAINERSHIP.md#pull-requests.
- [x] I added/updated unit tests for my changes.
- [x] I added/updated integration tests for my changes.
- [x] I ran the integration tests.
- [x] I tested my changes in Node, Deno, and the browser.
- [x] I viewed documents produced with my changes in Adobe Acrobat, Foxit Reader, Firefox, and Chrome.
- [x] I added/updated doc comments for any new/modified public APIs.
- [x] My changes work for both new and existing PDF files.
- [x] I ran the linter on my changes.
What's the status on this PR? I think this is a great addition to pdf-lib, we desperately need this.
Thank you.
Sadly, there does not seem to have been any activity from the core PDF-Lib maintainers for more than one year. For now, we maintain our own fork of this library (@ecervo/pdf-lib) until PRs start to be processed again, or a new fork starts to gain traction.
Sadly, there does not seem to have been any activity from the core PDF-Lib maintainers for more than one year. For now, we maintain our own fork of this library (@ecervo/pdf-lib) until PRs start to be processed again, or a new for starts to gain traction.
Thank you very much for your reply. Is your fork a private repo?
No, it's not:
https://github.com/e-cervo/pdf-lib https://www.npmjs.com/package/@ecervo/pdf-lib
No, it's not:
https://github.com/e-cervo/pdf-lib https://www.npmjs.com/package/@ecervo/pdf-lib
Thank you very much!
hi, is there any chance this get merged?
@phipla Thank you. Your fork saved me from having to find another library. The overprint was especially nice and important.