Problem with duplicate objects when exporting to PDF

Could someone help me figure out how to upload to PDF? I draw a simple circle and export the result to PDF. When I open the file in a vector program, I see that two objects have been unloaded at the same place. One object is invisible because it has no outline. The second object with an outline. And both without filling, although in the code I used fill(0). How can I get rid of this double upload? When there are a lot of objects, and their number doubles in this way, this becomes a problem.

import processing.pdf.*;
size(400, 400);
noStroke();
fill(0);
beginRecord(PDF, fileName);
background(255);
circle(100, 100, 10);
endRecord();

And the second question, can I set the file size when uploading to PDF? My default is always A4, and I would like to be able to change this, but I can’t find how.

Hello @S0r0ka,

There is a PDF Export Library reference here:

Example:

import processing.pdf.*;
size(400, 400);

beginRecord(PDF, "test.pdf");
// Put code here between *begenRecord()* and *EndRecord()*
noStroke();
fill(0);
// And so on...
endRecord();

The code example you provided does not run; you need to have a fimeName which is a String such as “test.pdf”

Please follow these instructions if you are posting code:
https://discourse.processing.org/faq#format-your-code

:)

1 Like

Thank you for your answer. I understand that vector graphics is scaled, but if I need some special proportions it’s not convenient to use other program to change file’s format. Do you mean I need to use createGraphics for this? I’m gonna try, thank you!

My code runs. This example is simplified, of course I use full path name in this string. It’s not a problem. Problem there is in finishing file.

Yes, this works! I was able to change file’s dimentions, thank you again!
So I still need to solve the first problem with duplicating)

Can you provide a simple example of the problem?

This is often called and MCVE:

:)

This is my code example:

import processing.pdf.*;

String fileName;

void setup()
{
  size(400, 400);
  noStroke();
  fill(0);
  fileName = "output/" + day()+hour()+minute() + "-###.pdf";
  beginRecord(PDF, fileName);
  background(255);
  circle(200, 200, 50);
}

void draw()
{
}

void keyPressed()
{
  if (key == 'P' || key == 'p')
  {
    endRecord();
  }
}

This is what I see at processing screen:
_Proc

This is what I have in pdf file:

This is what is in vector program when I open pdf file - two objects, one is invisible (I move second to the right to show it here):

So I have two curves in my unloading.

Hello,

A related topic:
https://discourse.processing.org/t/how-do-i-get-my-pdf-to-render-properly/37349/5

Try this:

import processing.pdf.*;

String fileName;

void setup()
  {
  size(400, 400);

  fileName = "output/" + day()+hour()+minute() + "-###.pdf";
  //noStroke();
  //fill(0);
  beginRecord(PDF, fileName);
  noStroke(); // Moved to here
  fill(0);    // Moved to here
  background(255);
  circle(200, 200, 50);
  endRecord();
  }

:)

1 Like

omg, it works! how simple))) thank you so much, you save me a lot of time!