Saving Sketch to PDF Issues

Hello-
I am trying to save my sketch to a pdf. When I follow the documentation exactly with a simple geometry, it works fine. However, I have a function that grabs a random shape and puts it on the screen in a loop. When I substitute the function (drawShapes():wink: for the simple rectangles I get an unreadable PDF and a long list of java runtime errors. Does anyone know what I am doing wrong? Thanks so much for the help! (not sure how to add the .svgs here for you to use …).

import processing.pdf.*;
float seedRandomizer = random(0, 10000);
int seed = int(seedRandomizer);
boolean run = false;
boolean record;

void setup() {
  size(1600, 900);
  beginRecord(PDF, "frame-"+seed+".pdf");
  randomSeed(seed);
  frameRate(3);
  background (#bf4748);
  chooseShapes();
}

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

  //save PDF works fine with these simple rects.
  //fill(0);
  //rect (100,100,400,400);
  //fill(255);
  //rect (400,400,600,600);
}

void keyPressed() {
  if (key == 'q' || key == 'Q');
  endRecord();

// Shapes Function/Tab
//GETTING SHAPES AND DRAWING TO SCREEN
//these are the things to randomize everything
int numShapes = 3;
PShape[] arrayOfShapes = new PShape[numShapes];
int randIndexShapes;
int randIndexFramecount;
//int randomIndexFont;

void chooseShapes() {
  randIndexFramecount = int(random(1, 20));  // selects a random frame //number which will be used to stop the loop in draw.
  randIndexShapes = int(random(0, arrayOfShapes.length));  // selects a //number from 0 to the number of shapes in the array. This gets used in //DRAW to select the shape file..
  println("arrayOfShapes.length is:", arrayOfShapes.length);

  for (int i = 0; i < arrayOfShapes.length; i ++) {
    //println (arrayOfShapes.length);
    arrayOfShapes[i] = loadShape( "shapesfolder/asset"+i +".svg"); // loads //the shapes into memory.
    arrayOfShapes[i].disableStyle(); // disables the style that came in from //Illustrator so I can style randomly in Processing. I do this so I can style it //here in processing.
  }
}
void drawShapes() {
  shapeMode(CENTER);
  noStroke();
  fill(0, 0, 0, random(10, 75));

  //setting up the variables used in draw
  float xPos = random(0, width);  //for placement, x position
  float yPos = random(0, height);  //for placement, y position
  float wSize = random(50, width);  //for placement, width
  float hSize = random (50, height);  //for placement, height
  float rVal = random(0, 0); // red value
  float bVAl = random(0, 0); // blue value
  float gVal = random(0, 0); // green value
  float tVal = random(0, 100); // opacity value
  


  // THIS STARTS THE DRAWING OF SHAPES
  translate (width/2, height/2);
  theta = random(180, 360);
  rotate(radians(theta));
  for (int i=0; i < arrayOfShapes.length; i++) {
    fill(rVal,bVAl,gVal,tVal);
    shape(arrayOfShapes[randIndexShapes], xPos, yPos, wSize, hSize);
  }
  if (randIndexFramecount == frameCount) {
    noLoop();
  }
}


}