Export large scale print file + web file

void mousePressed() { 
  saveFrame("balls-#####.png");
   surface.setResizable(true);
   surface.setSize(7200, 9600);
   pdf = (PGraphicsPDF)beginRecord(PDF, "test.pdf");
   endRecord();
   exit();
} 

But the pdf can’t be opened :-/
I created a generative scipt. In case I run the code twice the result is slightly different.