Hi PhiLho,
Following your suggestion I solve my problem,
- import processing.pdf.*;
- PGraphicsPDF pg;
- boolean doSave = false;
- int canvasW = 320;
- int canvasH = 240;
- void setup() {
- size(640, 480);
- pg = (PGraphicsPDF)createGraphics(canvasW, canvasH, PDF, "ellipse.pdf");
- }
- void draw() {
- if (doSave) {
- println("saving pdf file");
-
- pg.beginDraw();
- pg.background(220, 20, 100);
- pg.stroke(255);
- pg.fill(0);
- pg.ellipse(canvasW / 2, canvasH / 2, 50, 50);
- pg.dispose();
- pg.endDraw();
-
- doSave = false;
- println("save complete");
- }
- }
- void keyPressed() {
- if (key == 's' || key == 'S') {
- doSave = true;
- }
- }
I can now create a pdf file of my desired size, many thanks!
Now I have another problem, how do I render to screen before saving to a file any ideas?
I can render a PGraphics using image() but no a PGraphicsPDF so I'm stuck there :P