Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

strokeWeight() and stroke() not working on PDF creation

$
0
0
Just a quick issue about PDF creation.

If you run the code below you will get 2 PDF files, one which is actually what you see on screen (lines on different weight and color) and another one which is not (all the lines in black a 1px weight).

Any idea how to get the PGraphics to export weight and color of the strokes?

I'm working on a generative graphics app, and part of my screen is the interface, so I would prefer to use PGraphics to export just the right area and avoid the PDF being bigger (xy size/format) than the necessary... in the example I'm just avoiding the right half of the screen, but the idea is that way I can also scale the output to the desired PDF size (so I don't need a huge screen if I want the output to be an A1 for instance)

    1. import processing.opengl.*;
    2. import processing.pdf.*;

    3. void setup() {
    4.   size(500, 500, OPENGL);
    5.   background(255);
    6.   PGraphics pdf;
    7.   pdf = createGraphics(250, 500, PDF, "wrong.pdf");
    8.   pdf.beginDraw();  
    9.   beginRaw(PDF, "right.pdf");

    10.   for (int i=1; i<25; i++) {
    11.     strokeWeight(i);
    12.     stroke(10*i);
    13.     line(10, 10*i*2, width/2-10, 10*i*2);
    14.     pdf.line(10, 10*i*2, width/2-10, 10*i*2);
    15.   }

    16.   // Switch off the exporter
    17.   pdf.dispose();
    18.   pdf.endDraw();

    19.   endRaw();
    20. }

    Any ideas on how to solve this, or achieve it in other way, will be much appreciated.

    Viewing all articles
    Browse latest Browse all 1768

    Trending Articles