Saving to PDF while using the copy() function

Hey,
I’m have written a small code for a sort of text-warping tool using PGraphics, PFont, and the copy() function. I would like to output “Many Frames Into One File (With Screen Display)” as explained in the PDF library, but I am now receiving the error code: “No copy() for PGraphicsPDF” when I run my code. Below is my code as it stands. Any thoughts on how to remedy this issue and export a PDF (or even just a very High-Res .png or .jpeg) of my screen display while using the copy() function?

PGraphics pg;
PFont font;

int on=1;
int move = 0;

float x;
float y;
float easing = 0.05;

import processing.pdf.*;

void setup(){
  size(800,800);
  background(0);
  
  beginRecord(PDF, "everything.pdf");
 
  font = createFont("governor.ttf", 300); 
  pg = createGraphics(800,800);
}

void draw() {
  float targetX = mouseX;    //Movement Easing
  float dx = targetX - x;
  x += dx * easing;
  
  float targetY = mouseY;
  float dy = targetY - y;
  y += dy * easing;
  
  pg.beginDraw();      //Draw Letters
  pg.background(0,0,0);
  pg.fill(255);
  pg.textFont(font);
  pg.textSize(150);
  pg.pushMatrix();
  pg.translate(x, y);
  pg.textAlign(CENTER, CENTER);
  pg.text("TEXT", 0, 0);
  pg.popMatrix();
  pg.endDraw();
  
   copy(pg, 0, move, width, 1, 0, move, width, 1);    // Copy/Paste
  
   move = move + 1;    //Advance Copy/Paste line
   
   if (move > height){
   move = 0;
   background(0); 
  }}
 
void mousePressed() {      //ON/OFF switch
  if(on<0){
  loop(); on=on*-1;
  }else{ noLoop();on=on*-1;}
}

void keyPressed() {      //End recording/Exit
  if (key == 'q') {
    endRecord();
    exit();
  }
}

I have not worked with PDFs so just exploring…

https://processing.org/reference/libraries/pdf/index.html
https://processing.org/reference/PGraphics.html

I took some examples from links and merged with yours and cut some code and this will save to a PDF when I hit ‘q’:

import processing.pdf.*;
PGraphics pg;

float x;
float y;
float easing = 0.05;

void setup() 
  {
  size(400, 400);
  beginRecord(PDF, "everything.pdf");
  pg = createGraphics(400, 400); 
  background(0);
  }

void draw() 
  {
  float targetX = mouseX;    //Movement Easing
  float dx = targetX - x;
  x += dx * easing;
  
  float targetY = mouseY;
  float dy = targetY - y;
  y += dy * easing;

  pg.beginDraw();      //Draw Letters
//  pg.background(0,0,0);
  pg.fill(255);
  pg.textSize(50);
  pg.pushMatrix();
  pg.translate(x, y);
  pg.textAlign(CENTER, CENTER);
  pg.text("TEXT", 0, 0);
  pg.popMatrix();
  pg.endDraw();
  
  image(pg, 0, 0);
  }

void keyPressed()
  {
  if (key == 'q') 
    {
    endRecord();
    exit();
    }
  }

:slight_smile:

Hey thanks for taking a look at this! However, looks like you removed the copy() function from the code which defeats the purpose a little bit. My goal is to be able to use the copy() function with a PGraphics element and export multiple frames of the animation to a PDF. thoughts?

This did save to a PDF when I pressed ‘q’.
I removed “copy” because it did not work.

You may want to consider saving frames:
https://processing.org/reference/saveFrame_.html

I do this for making animated GIFs:

:slight_smile: