Does PDF Not Play With Matrices?
in
Core Library Questions
•
1 year ago
Hi,
I had a rather complex Processing program and thought it would be nice to output to a PDF in addition to the screen. Unfortunately it blows up with a "missing a PopMatrix() error"
So I created the following very simple program that preserves the core characteristics of my real program in order to see what would happen:
The program works fine until I add the begin and end record statements for the PDF. When I press 'x' to save, I get this error:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: missing a popMatrix() to go with that pushMatrix()
Taking another charge at it, I modified the program as follows:
The popMatrix error message goes away but is replaced with the following message:
isRecording(), or this particular variation of it, is not available with this renderer.
Note that these errors do not occur if I write to the PDF file using size(w, h, PDF, "filename");
instead of the begin and end record statements.
Unfortunately this method means no screen output and I really do need to be able to see what I'm doing before deciding whether or not to create the PDF.
Any suggestions would be appreciated. Thanks
Best Regards, Jim
I had a rather complex Processing program and thought it would be nice to output to a PDF in addition to the screen. Unfortunately it blows up with a "missing a PopMatrix() error"
So I created the following very simple program that preserves the core characteristics of my real program in order to see what would happen:
- import processing.pdf.*;
- float offsetX,offsetY;
- boolean wipe=true;
- void setup(){
- size(1200,800);
- offsetX=width/2;
- offsetY=height/2;
- beginRecord(PDF, "testingpdf.pdf");
- noLoop();
- }
- void draw(){
- drawit();
- noLoop();
- }
- void drawit() {
- float x,y;
- rectMode(CENTER);
- translate(offsetX,offsetY);
- for(int n=0; n < 50; n++) {
- fill(random(0,255),random(0,255),random(0,255));
- x = random(0,width);
- y = random(0,height);
- pushMatrix();
- translate(x,y);
- rotate(radians(random(0,TWO_PI)));
- rect(0,0,random(20,100),random(20,100));
- popMatrix();
- }
- }
- void mousePressed() {
- offsetX=mouseX;
- offsetY=mouseY;
- if(wipe) background(255);
- loop();
- }
- void keyPressed() {
- if(key=='x' || key=='X') {
- // output file
- endRecord();
- println("Quit and Saved ");
- exit();
- }
- }
The program works fine until I add the begin and end record statements for the PDF. When I press 'x' to save, I get this error:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: missing a popMatrix() to go with that pushMatrix()
Taking another charge at it, I modified the program as follows:
- import processing.pdf.*;
- float offsetX,offsetY;
- boolean wipe=true;
- void setup(){
- size(1200,800);
- offsetX=width/2;
- offsetY=height/2;
- beginRecord(PDF, "testingpdf.pdf");
- }
- void draw(){ }
- void drawit() {
- float x,y;
- rectMode(CENTER);
- translate(offsetX,offsetY);
- for(int n=0; n < 50; n++) {
- fill(random(0,255),random(0,255),random(0,255));
- x = random(0,width);
- y = random(0,height);
- pushMatrix();
- translate(x,y);
- rotate(radians(random(0,TWO_PI)));
- rect(0,0,random(20,100),random(20,100));
- popMatrix();
- }
- }
- void mousePressed() {
- offsetX=mouseX;
- offsetY=mouseY;
- if(wipe) background(255);
- drawit();
- }
- void keyPressed() {
- if(key=='x' || key=='X') {
- // output file
- endRecord();
- println("Quit and Saved ");
- exit();
- }
- }
The popMatrix error message goes away but is replaced with the following message:
isRecording(), or this particular variation of it, is not available with this renderer.
Note that these errors do not occur if I write to the PDF file using size(w, h, PDF, "filename");
instead of the begin and end record statements.
Unfortunately this method means no screen output and I really do need to be able to see what I'm doing before deciding whether or not to create the PDF.
Any suggestions would be appreciated. Thanks
Best Regards, Jim
1