# Saving specific frames into one PDF, using frameCount and array

**URL:** <https://discourse.processing.org/t/saving-specific-frames-into-one-pdf-using-framecount-and-array/22060>\
**Category:** Coding Questions\
**Created:** [June 22, 2020, 1:00pm UTC](https://discourse.processing.org/t/saving-specific-frames-into-one-pdf-using-framecount-and-array/22060 "2020-06-22T13:00:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vvvr](https://avatars.discourse-cdn.com/v4/letter/v/94ad74/32.png) [@vvvr](https://discourse.processing.org/u/vvvr)\
**Post date:** [June 22, 2020, 1:00pm UTC](https://discourse.processing.org/t/saving-specific-frames-into-one-pdf-using-framecount-and-array/22060/1 "2020-06-22T13:00:18Z")

</div>

Hi, I am new to Processing and using the examples in the PDF library I am trying to write a code for one of my artworks. I need to save into one PDF a particular selection of frames.

I have adapted the code for the example “PDF Multiple pages” and managed to write something that does the trick.  
I’ll add the code below.

My question: You can see from the example that I have created an array with the frame count numbers where I would like to have a new page in my PDF.  
What I can’t work out is how to change “fc[5]” on line 31

```auto
else if ( frameCount == fc[5] )

```

into a general test that asks the question: if the frameCount is ANY of the integers listed in the array fc then do pdf.nextPage.  
So I would like it to cycle through all the values in the array. I have tried to use the “for” loop but had no success.

My code:

```auto
import processing.pdf.*;
PFont font;
int [] fc = { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 }; // array of framecounts to save in PDF

void setup() {
  size(400, 400, PDF, "filename02_##.pdf"); 
}

void draw() {
  
  line(0, 0, frameCount * 4, height);
  fill(0);
  textSize(8);
  text( frameCount, frameCount*4, (height-10)); 
  println(frameCount);
    
  PGraphicsPDF pdf = (PGraphicsPDF) g; // Get the renderer
  

  // this creates 5 pages, each with all frames up to a frame count
  if (frameCount == fc[9]) {
    println((frameCount)+ " EXIT" );
    exit();
  } else if ( frameCount == fc[5] ) {//this records frames 1-8 on one page. INSTEAD OF typing fc[5] how can I cycle through the values of the array?
    pdf.nextPage ();
    } else if ( frameCount == fc[6] ) { //this records frames 9-13 on one page
    pdf.nextPage ();
    } else if ( frameCount == fc[7] ) {//this records frames 14-21 on one page
    pdf.nextPage ();
    } else if ( frameCount == fc[8] ) { //this records frame 22-34 
    pdf.nextPage (); // and the last page records frame 35-98, making it 5 page PDF.
    
  } 
}

```

Many thanks for your time!

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [June 22, 2020, 3:57pm UTC](https://discourse.processing.org/t/saving-specific-frames-into-one-pdf-using-framecount-and-array/22060/2 "2020-06-22T15:57:35Z")

</div>

If I understand correctly, I would change:

> [@vvvr](#):
>
> `else if ( frameCount == fc[5] )`

for the following:

`else if ( inArray(frameCount, fc[5]) )`

where

```java
boolean inArray(int frmCtr, int[] newPageFrameArray){

   for(int i=0; i<newPageFrameArray).length; i++){
      if(frmCtr==newPageFrameArray[i]){
        return true;
      }
   }

   return false;
}

```

As an altrnative, you can use _ **IntList** _ instead of an array and then you can use the method `hasValue()` to check if the list contains the frame number you want to check. More in the [IntList reference](https://processing.org/reference/IntList.html).

Kf

---

<div class="post-metadata">

**Author:** ![vvvr](https://avatars.discourse-cdn.com/v4/letter/v/94ad74/32.png) [@vvvr](https://discourse.processing.org/u/vvvr)\
**Post date:** [June 22, 2020, 4:20pm UTC](https://discourse.processing.org/t/saving-specific-frames-into-one-pdf-using-framecount-and-array/22060/3 "2020-06-22T16:20:06Z")

</div>

Hi @kfrajer thanks for the reply. I have not yet come across the IntList but that looks that that is just what I need. I’ll check it out and let you know.  
W.

---

<div class="post-metadata">

**Author:** ![vvvr](https://avatars.discourse-cdn.com/v4/letter/v/94ad74/32.png) [@vvvr](https://discourse.processing.org/u/vvvr)\
**Post date:** [June 22, 2020, 10:48pm UTC](https://discourse.processing.org/t/saving-specific-frames-into-one-pdf-using-framecount-and-array/22060/4 "2020-06-22T22:48:01Z")

</div>

Hi @kfrajer, it worked out beautifully!  
Thanks for pointing out the IntList option!  
W.

```auto
//Multiple Pages (No Screen Display)

/*BASED ON THE EXAMPLE OF PDF Multiple pages:
Using Intlist for the frames to be saved in the PDF

*/
import processing.pdf.*;
PFont font;
IntList FibonacciList;

void setup() {
  FibonacciList = new IntList (1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144);
  
  println (FibonacciList);
  size(400, 400, PDF, "filename03_##.pdf"); 
}

void draw() {
  
  line(0, 0, frameCount *2, height);
  fill(0);
  textSize(8);
  text( frameCount, frameCount *2.5, (height-10)-(frameCount*2.5)); 
  println(frameCount);
    
  PGraphicsPDF pdf = (PGraphicsPDF) g; // Get the renderer
  
  if (frameCount == FibonacciList.max() ) { // exit at end of list
    println((frameCount)+ " EXIT" );
    exit();
  } else if (FibonacciList.hasValue(frameCount)) { // check if a particular frame count is part of the list
      pdf.nextPage (); 
  } 
}

```
