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

Re : How to save a PDF from a specific area of the app window?

$
0
0
Hi PhiLho,

Following your suggestion I solve my problem,
  1. import processing.pdf.*;

  2. PGraphicsPDF pg;

  3. boolean doSave = false;
  4. int canvasW = 320;
  5. int canvasH = 240;

  6. void setup() {
  7.   size(640, 480);
  8.   pg = (PGraphicsPDF)createGraphics(canvasW, canvasH, PDF, "ellipse.pdf");
  9. }

  10. void draw() {
  11.   if (doSave) {
  12.     println("saving pdf file");
  13.     
  14.     pg.beginDraw();
  15.     pg.background(220, 20, 100);
  16.     pg.stroke(255);
  17.     pg.fill(0);
  18.     pg.ellipse(canvasW / 2, canvasH / 2, 50, 50);
  19.     pg.dispose();
  20.     pg.endDraw();
  21.     
  22.     doSave = false;
  23.     println("save complete");
  24.   }
  25. }

  26. void keyPressed() {
  27.   if (key == 's' || key == 'S') {
  28.     doSave = true;
  29.   }
  30. }
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

Viewing all articles
Browse latest Browse all 1768

Trending Articles