# Renaming PDF generated files

**URL:** <https://discourse.processing.org/t/renaming-pdf-generated-files/16164>\
**Category:** Coding Questions\
**Created:** [December 5, 2019, 7:52pm UTC](https://discourse.processing.org/t/renaming-pdf-generated-files/16164 "2019-12-05T19:52:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [December 5, 2019, 7:52pm UTC](https://discourse.processing.org/t/renaming-pdf-generated-files/16164/1 "2019-12-05T19:52:32Z")

</div>

Unable to find the answer to this in REFERENCE section.

I have a very simple program to generate **random color block overlaps**.

Currently set up to record a PDF of each instance when code runs.

**How do I generate a new name for the PDF each time code is run** (otherwise it’s the same file name each time and overwrites the previous PDF file)?

CURRENT CODE BELOW:

```auto
import processing.pdf.*;

float randomH1 = random(300, 400);

void setup() {
  size (400, 600);
  noLoop();
  beginRecord(PDF, "filename.pdf");
}

void draw() {
  background (255);
  noStroke();

  fill(150, 220, random(255), 150);
  rect(0, 0, width, random(150, 275));

  rectMode(CENTER);
  fill(random(255), 185, 185, 150);
  rect(width/2, height/2, width, random(150, 250));

  fill(random(255), 225, 90, 150);
  quad(0, height, width, height, width, randomH1, 0, randomH1);

  endRecord();
}

```

Many thanks to anyone who can help me with this!  
🙂

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [December 5, 2019, 8:59pm UTC](https://discourse.processing.org/t/renaming-pdf-generated-files/16164/2 "2019-12-05T20:59:36Z")

</div>

Is it possible to create a counter that I could attach to the filename?

For example:

`beginRecord (PDF, "filename + counter.pdf"`

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 5, 2019, 9:16pm UTC](https://discourse.processing.org/t/renaming-pdf-generated-files/16164/3 "2019-12-05T21:16:45Z")

</div>

Try this:

```auto
beginRecord(PDF, nf(year())+nf(month())+nf(day(),2)+nf(hour(),2)+nf(minute(),2)+".pdf");
}

```

🙂

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [December 5, 2019, 9:34pm UTC](https://discourse.processing.org/t/renaming-pdf-generated-files/16164/4 "2019-12-05T21:34:28Z")

</div>

> [@glv](#):
>
> (PDF, nf(year())+nf(month())+nf(day(),2)+nf(hour(),2)+nf(minute(),2)+“.pdf”); }

Thank you!!  
That works nicely.  
Plus I added seconds to be able to save a new named file every second.  
😂
