How to export to PDF without separating stroke and fill into two objects?

Hello again! Let's say I want to export an ellipse to PDF with stroke and fill. The library does so, by creating two separate objects: one for stroke and another for fill. Is it possible to create only one with the two properties? If not, any workaround? Like a script for Illustrator or something? Thank you!

Answers

  • Indeed, I can reproduce your problem with a simple adaptation of the OneFrame example:

    import processing.pdf.*;
    
    size(600, 600);
    
    beginRecord(PDF "H:/Temp/output.pdf"); 
    
    background(255);
    stroke(0, 20);
    strokeWeight(20.0);
    fill(#456789);
    rect(200, 200, 300, 300);
    
    endRecord();
    

    and by opening the result with Inkscape. It shows two objects, one for the interior of the rectangle, another for the stroke itself;

    I tried with my library, P8gGraphicsSVG:

    import org.philhosoft.p8g.svg.P8gGraphicsSVG;
    
    size(600, 600);
    
    beginRecord(P8gGraphicsSVG.SVG, "H:/Temp/output.svg"); 
    
    background(255);
    stroke(0, 20);
    strokeWeight(20.0);
    fill(#456789);
    rect(200, 200, 300, 300);
    
    endRecord();
    

    and I end with a similar result.

    Conclusion: since both libraries use a similar process, leveraging the underlying Java library (iText, Batik) to be called each time a Java2D graphics method is called, I think that's the Processing way to handle such drawing. So, it cannot be avoided at generation time.

    Not sure if there is an easy way to transform such generated file: a script must detect the two shapes are actually the same and must be merged. Doable, not simple.

  • edited March 2014

    If you open the document in Illustrator, the layers are arranged by drawing order: the first thing to be drawn in Processing, gets to the bottom of the layers. So for an object #1, you get it's fill and stroke, then for object #2 it's fill and stroke and so on. For example, with this:

    import processing.pdf.*;
    
    size(300, 300);
    
    beginRecord(PDF, "example.pdf");
    
    strokeWeight(5);
    
    stroke(#30CCAA);
    fill(#202020);
    rect(50, 50, 75, 75);
    
    stroke(#FF50BB);
    fill(#202020);
    rect(50, 150, 75, 75);
    
    stroke(#202020);
    fill(#FF50BB);
    rect(150, 50, 75, 75);
    
    stroke(#202020);
    fill(#30CCAA);
    rect(150, 150, 75, 75);
    
    endRecord();
    


    You get this:

    Screen Shot 2014-03-10 at 09.40.25


    Since the Clipping Path is always removed you get a sequence of shapes that you can either group, or even better, combine.

    Illustrator supports JavaScript... But I'm barely new to programming languages, so I can't offer a better answer right now. I've seen some scripts which ungroup/group layers inside Illustrator, and it didn't seem that hard... If I come up with something, I'll share it with everybody.

  • Hi there!

    The other day I was working with openFrameworks and the same issue appeared. To solve this, I did a really simple and specific Illustrator sketch to combine the two paths. You can get it here.

    Like I said before, it's just something I did to solve my specific problem. In openFrameworks, you don't get a Clipping Path and Clip Group, so this sketch won't work with a PDF exported from Processing, out-of-the-box. But it's enough to get you started, or to, at least, realize that you going to face this issue some day.

Sign In or Register to comment.