Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Separation colors #1322

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

phipla
Copy link

@phipla phipla commented Oct 12, 2022

What?

This PR adds support for separation colors in PDF-LIB, and answers the following issue request: #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 in PDFDocument that allows for embedding said object.
  • Define a method in PDFPage that allows to reference a previously-embedded PDFSeparation 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 and CS 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

Screenshot 2022-10-12 at 15 34 09

Suggested Reading?

Yes

Anything Else?

No

Checklist

  • I read CONTRIBUTING.md.
  • I read MAINTAINERSHIP.md#pull-requests.
  • I added/updated unit tests for my changes.
  • I added/updated integration tests for my changes.
  • I ran the integration tests.
  • I tested my changes in Node, Deno, and the browser.
  • I viewed documents produced with my changes in Adobe Acrobat, Foxit Reader, Firefox, and Chrome.
  • I added/updated doc comments for any new/modified public APIs.
  • My changes work for both new and existing PDF files.
  • I ran the linter on my changes.

@Jeordy
Copy link

Jeordy commented Feb 3, 2023

What's the status on this PR? I think this is a great addition to pdf-lib, we desperately need this.

Thank you.

@phipla
Copy link
Author

phipla commented Feb 7, 2023

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.

@Jeordy
Copy link

Jeordy commented Feb 7, 2023

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?

@phipla
Copy link
Author

phipla commented Feb 7, 2023

@Jeordy
Copy link

Jeordy commented Feb 7, 2023

@el-j
Copy link

el-j commented Apr 16, 2024

hi, is there any chance this get merged?

@styks1987
Copy link

styks1987 commented Apr 19, 2024

@phipla Thank you. Your fork saved me from having to find another library. The overprint was especially nice and important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants