# Processing saving empty PDF

**URL:** <https://discourse.processing.org/t/processing-saving-empty-pdf/22315>\
**Category:** Coding Questions\
**Created:** [July 2, 2020, 7:08am UTC](https://discourse.processing.org/t/processing-saving-empty-pdf/22315 "2020-07-02T07:08:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TimoL](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@TimoL](https://discourse.processing.org/u/TimoL)\
**Post date:** [July 2, 2020, 7:08am UTC](https://discourse.processing.org/t/processing-saving-empty-pdf/22315/1 "2020-07-02T07:08:19Z")

</div>

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?

```auto
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");
  }
}

```

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [July 2, 2020, 8:40am UTC](https://discourse.processing.org/t/processing-saving-empty-pdf/22315/2 "2020-07-02T08:40:31Z")

</div>

Hi @TimoL,

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

---

<div class="post-metadata">

**Author:** ![TimoL](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@TimoL](https://discourse.processing.org/u/TimoL)\
**Post date:** [July 2, 2020, 8:58am UTC](https://discourse.processing.org/t/processing-saving-empty-pdf/22315/3 "2020-07-02T08:58:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [July 2, 2020, 9:12am UTC](https://discourse.processing.org/t/processing-saving-empty-pdf/22315/4 "2020-07-02T09:12:44Z")

</div>

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

```auto
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();
  }
}

```

---

<div class="post-metadata">

**Author:** ![TimoL](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@TimoL](https://discourse.processing.org/u/TimoL)\
**Post date:** [July 2, 2020, 9:22am UTC](https://discourse.processing.org/t/processing-saving-empty-pdf/22315/5 "2020-07-02T09:22:16Z")

</div>

> [@jb4x](#):
>
> ```auto
> 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();
> }
> }
> 
> ```

Oh I see! thanks you so much 🙂
