Processing saving empty PDF

I’ve run into this problem where my pdf is coming out blank even though there is stuff on the screen.

I think it has to do with how I’m drawing to the canvas using mousePressed.

any ideas?

import processing.pdf.*;
boolean record = false;


void setup() {
  size(500, 500);
  background(255);
}



void draw () {
  if (record) {
    beginRecord(PDF, "frame-####.pdf");
  }


  if (record) {
    endRecord();
    record = false;
  }
  
}


void mousePressed() {
  circle(mouseX, mouseY, 50);
}



void keyPressed() {
  if (key == 's') {
    record = true;
    println("SAVED");
  }
}

1 Like

Hi @TimoL,

You need to start the recording before you draw on the screen for the capture to work.

hmm

I’ve tried initialising record as true but I still get a blank pdf.

Btw if you run the code and then click a few times to draw circles then press ‘s’ to save a frame the frame is blank.

any hints

Even if you set it to true at the top, the first time you enter the draw loop it is set to false.

import processing.pdf.*;

void setup() {
  size(500, 500);
  background(255);
  beginRecord(PDF, "frame-####.pdf");
}

void draw () {
}

void mousePressed() {
  circle(mouseX, mouseY, 50);
}

void keyPressed() {
  if (key == 's') {
    endRecord();
    exit();
  }
}
1 Like

Oh I see! thanks you so much :slight_smile: