CMYK export from Processing - what's the latest?

edited March 2018 in How To...

I have a project that outputs geometry for print. I would like to output a PDF with print-ready CMYK colors. In my current workflow I have to use Adobe Illustrator simply to assign proper CMYK colors to the PDF output before print. I want Adobe out of my toolchain and I want my processing sketch to be able to output print-ready PDFs.

Andreas Gysin has created a solution for this, but it is no longer maintained and does not appear to work in Processing 3. I was hoping I could update it to work with Processing 3, but I don't know what I'm doing. There are lots of deprecated functions and changes and I don't understand the code well enough or the changes between P1, P2, P3...

I understand that Java supports CMYK color spaces and ICC profiles, but I am floundering with implementation. I haven't been able to get any of the example code running and I'm a bit out of my depth. Still haven't figured out how to instantiate a ColorSpace let alone use it for outputting colors to a PDF.

I thought I could export SVGs and use a text editor to replace the colors in the XML -- but SVG doesn't seem to support CMYK properly. I can kludge something together so I can use a non-Adobe editor, but the workflow becomes untenable.

I would be thrilled if anyone could give me some direction on this. What would I need to do to update Andreas Gysin's CMYK code for P3? Am I barking up the wrong tree with Java ColorSpace? Once I get a 4 component color model working, how do I ensure those colors are exported in the PDF? This seems like a simple problem, but no easy answers are forthcoming. Any avenues of research, high level code, suggestions or examples would really help me get past this roadblock. Thank you.

Tagged:

Answers

  • Andreas Gysin has created a solution for this

    Can you provide a link to this reference?

    Kf

  • that's doesn't look like a library but a class that you can just add to your sketch. the three directories there all contain the SAME PDF.pde file, which the other .pde file uses via something like

    PDF pdf = new PDF(this, mm(210), mm(297), sketchPath(System.currentTimeMillis() + ".pdf")); 
    
  • edited March 2018

    which should make it easier to port to P3. that said, it is 5 years old.

  • edited March 2018

    The header notes on the PDF.pde class tab file says

    A slightly modified PGraphicsPDF class

    Perhaps diff Gysin's modifications

    https://github.com/ertdfgcvb/CMYK/blob/master/cmyk/PDF.pde

    ...against the appropriate original version of PGraphics PDF from 2013

    https://github.com/processing/processing/commits/master/java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java

    ...and once you know what was changed, apply those changes to the latest version?

    https://github.com/processing/processing/blob/master/java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java

    (I'm assuming these links are right based on a very quick search, but confirm that)

  • ok, so far i have:

    added

    import processing.awt.PGraphicsJava2D;
    

    to the top of PDF.pde

    added

    super.setSize((int)w, (int)h);
    

    to top of PDF.pde setSize(float w, float h) { because otherwise i was getting

    java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
        at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1016)
        at java.awt.GraphicsConfiguration.createCompatibleImage(GraphicsConfiguration.java:186)
        at processing.awt.PGraphicsJava2D.checkImage(PGraphicsJava2D.java:328)
        at processing.awt.PGraphicsJava2D.beginDraw(PGraphicsJava2D.java:338)
        at cmyk$PDF.beginDraw(cmyk.java:585)
    

    i also had to comment out allocate() method and the call to it in setSize() because it's no longer in the parent class

    i'm currently getting

    com.lowagie.text.exceptions.IllegalPdfSyntaxException: Unbalanced begin/end text operators.
        at com.lowagie.text.pdf.PdfContentByte.endText(Unknown Source)
        at com.lowagie.text.pdf.PdfDocument.newPage(Unknown Source)
        at com.lowagie.text.Document.newPage(Unknown Source)
        at cmyk$PDF.nextPage(cmyk.java:745)
    
  • as i said above, the github project is 3 directories, each a complete processing sketch. i'm using the cmyk directory for testing.

    i'm getting a non-zero pdf as output, but nothing is displayed when i open it.

  • ...and once you know what was changed, apply those changes to the latest version?

    lots of style changes make this complicated... 8(

  • Oof. Yeah, the "diff" doesn't look simple to resolve at all.

    Maybe reach out to the original author? Could be worth a shot....

  • actually, everything is nicely marked with his initials AG so it shouldn't be too hard just to copy the cmyk methods over to the new PGraphicsPDF file.

    will try that tomorrow

  • actually, did it now. seems ok, but then i don't really know what i'm doing.

    https://github.com/acdean/CMYK/blob/master/cmyk/PDF.pde

    for an example see the cmyk.pde sketch in the same directory

  • Answer ✓

    Copied PDF.pde to the other two example project directories.

    Replaced example outputs with newly generated files. (the font is missing so it uses the default, which isn't as nice, otherwise it looks identical).

    https://github.com/acdean/CMYK

  • (i'm going to try and make the cmyk version extend the original PDF file, rather than copying 80% of the code)

  • edited March 2018

    Very cool that you are taking this on, @koogs. If it works it seems like it might even be a proposed pull request...? edit: by which I mean -- I wonder if this CMYK support could easily be pushed back upstream to the original Processing PDF.

  • Very cool indeed! Thank you! The code runs on P3 and the output displays proper 4-component and spot colors. I really appreciate your efforts on this!

  • @koogs Do you see it would be possible to be introduce in the current Processing core?

    Kf

Sign In or Register to comment.