galkahana / HummusJS

Node.js module for high performance creation, modification and parsing of PDF files and streams
http://www.pdfhummus.com
Other
1.14k stars 169 forks source link

Pantone color support #350

Open mattgaspar opened 5 years ago

mattgaspar commented 5 years ago

Do you have any examples of how to use a Pantone color?
I'm guessing it would require use of the SCN operator but I'm a bit lost beyond that! Are you aware of any way to obtain the numbers necessary for that operation from a Pantone color code? Any libraries for that or is that all copyright protected?

Or if the Pantone color is used in a logo I'm inserting into the page, can I get a reference from the xObject from createFormXObjectsFromPDF()

Thanks for any help and for creating this great library!

galkahana commented 5 years ago

You will need to define a colorspace that defines the pantone as custom color, and provide fallback on rgb/cmyk in it. then register it on the page. once you have that then you can use the content context scn and SCN operators (which match those operators of PDF) to use it. note that high level operations for drawing primitives or text only hav rgb/cmyk support, so you'll have to use the other more low level operators (again, matching the PDF operators) to draw them. check out the PDF specs for the entities to define, then hummus will provide:

  1. low level obejcts construction (for the color space) - https://github.com/galkahana/HummusJS/wiki/Extensibility
  2. pdf operators in hummus - https://github.com/galkahana/HummusJS/wiki/Use-the-pdf-drawing-operators
galkahana commented 5 years ago

missed your note on createFormXObjectsFromPDF. it will return an array of objectIDs, which is the form object ids, per page,, you can then use it in doXObject, like this:

const xobjectForm = resizeWriter.createFormXObjectsFromPDF(file_path, hummus.ePDFPageBoxMediaBox)
.....
pageContent.q()
      .cm(a,b,c,d,t1,t2)
      .doXObject(page.getResourcesDictionary().addFormXObjectMapping(xobjectForm[0]))
      .Q()