Adding background when outputting PDF in Processing 4 JAVA

With Processing 4, I can save my data in PDF format. But it doesn’t happen when I try to add an image behind the PDF output. I have to use beginRecord() function because I need to record data continuously.

public void setup() 
{  
  GPointsArray pointsECG = new GPointsArray(nPoints1);
 
  size(1024, 600, JAVA2D);
  backgroundImage = loadImage(ecgeniyi.png);
  heightHeader=100;
  println("Height:"+height);

  totalPlotsHeight=height-heightHeader;
  
  makeGUI();
  surface.setTitle("Healthy Race");
  PImage icon = loadImage("hr.png");
  surface.setIcon(icon);
  
  plot1 = new GPlot(this);
  plot1.setPos(20,200);
  plot1.setDim(width-40, (totalPlotsHeight/3)-10);
  plot1.setBgColor(0);
  plot1.setBoxBgColor(0);
  plot1.setLineColor(color(255, 255, 255));
  plot1.setLineWidth(1);
  plot1.setMar(0,0,0,0);

  for (int i = 0; i < nPoints1; i++) 
  {
 
    pointsECG.add(i,0);

  }
  
  plot1.setPoints(pointsECG);

  for (int i=0; i<windowSize; i++) 
  {

    ch1Data[i] = 0;
    ch2Data[i] = 0;
    
  }

}


public void draw() 
{
  background(255);
 // background(19,75,102);

  GPointsArray pointsPlot1 = new GPointsArray(nPoints1);


  if (startPlot)                             // If the condition is true, then the plotting is done
  {
    for(int i=0; i<nPoints1;i++)
    {    
      pointsPlot1.add(i,ch1Data[i]);
    }
  } 
  else                                     // Default value is set
  {
  }

  plot1.setPoints(pointsPlot1);

  
  plot1.beginDraw();
  plot1.drawBackground();
  plot1.drawLines();
  plot1.endDraw();

if(c == true){
if(f == true){
  pdf.nextPage();
  f = false;
}}

  
}

public void RecordData()
{
      c = true;

  pdf = (PGraphicsPDF)beginRecord(PDF, "Lines.pdf");
  pdf.beginDraw();
  pdf.background(255);
  pdf.image(backgroundImage, 0, 0, pdf.width, pdf.height); 
  pdf.endDraw();

  pdf.dispose();
}


public void EndRecord()
{
    c = false;

  endRecord();
}

Here RecordData(); I want to see an image in the background while drawing PDF lines in the function.

  1. The code that you posted won’t run on my system. There must be additional code that you didn’t post.
  2. Is the image an ecg paper grid?
  3. The following is a screen shot of a .pdf file with a .jpg background. Is this what you are asking?

  1. In the posted code RecordData() is never called.