# Adding background when outputting PDF in Processing 4 JAVA

**URL:** <https://discourse.processing.org/t/adding-background-when-outputting-pdf-in-processing-4-java/42063>\
**Category:** Coding Questions\
**Created:** [May 24, 2023, 12:17pm UTC](https://discourse.processing.org/t/adding-background-when-outputting-pdf-in-processing-4-java/42063 "2023-05-24T12:17:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cans](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cans](https://discourse.processing.org/u/cans)\
**Post date:** [May 24, 2023, 12:17pm UTC](https://discourse.processing.org/t/adding-background-when-outputting-pdf-in-processing-4-java/42063/1 "2023-05-24T12:17:53Z")

</div>

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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [May 25, 2023, 1:31am UTC](https://discourse.processing.org/t/adding-background-when-outputting-pdf-in-processing-4-java/42063/2 "2023-05-25T01:31:08Z")

</div>

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?

 ![scrnShot](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/2/a/2ac982047e3841cae5fc1854b45de185d0606d12.jpeg)

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