pdf-lib icon indicating copy to clipboard operation
pdf-lib copied to clipboard

[Feature Request] Spot color support

Open ddcovery opened this issue 4 years ago • 1 comments

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:

  • A name (i.e. "MyGoldSC")
  • A tint ( 0 to 1 ): similar to the values of a C, M, Y o K that tells to the printer how mutch of the tint must be used
  • An alternate color: It is the color used when the device doesn't recognize the spotcolor (i.e.: When PDF must be rendered on screen by acrobat reader, ilustrator, inkscape, ...)

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),
})

ddcovery avatar May 14 '20 12:05 ddcovery

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.

kimmobrunfeldt avatar May 14 '20 14:05 kimmobrunfeldt