Hopding / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
6.89k stars 656 forks source link

[Feature Request] Spot color support #444

Open ddcovery opened 4 years ago

ddcovery commented 4 years ago

Why

Spot colors are "named tints" that the printer or post-processors recognizes. Spot colors are used, for example, to paint with "varnish" or specific "gold" tint, but to recognize "cutlines" too.

An spot color has, basically:

Reference

Specifications can be found under "PDF Reference 1.7" > "4.5.5 Special Color Spaces" > "Separation Color Spaces"

An example of codification

5 0 obj       % Color space
  [ /Separation
      /MyGoldSC
      /DeviceCMYK
     12 0 R
  ] 
endobj
12 0 obj               % Tint transformation function
  <<  /FunctionType  2
        /Domain: [0.0, 1.1]
        /C0  [0.0 0.0 0.0 0.0]
        /C1  [0.0 0.17 0.74 0.17 ]
        /N 1
       /Lentgh ...
   >>
  ...
endobj

How to use?

A possibility:

var myGoldSpotColor = await pdfDoc.embedSeparation( "MyGoldSC", cmyk(0,0.17,0.74, 0.17), 1);
...

firstPage.drawText("This golden text was added with JavaScript!", {
  x: 5,
  y: height / 2 + 300,
  size: 50,
  font: helveticaFont,
  color: myGoldSpotColor,
  rotate: degrees(-45),
})
kimmobrunfeldt commented 4 years ago

I found a PR for spot color support in PDFKit repository: https://github.com/foliojs/pdfkit/pull/1059. The code might help in creating this feature.