Saving multiple PDF files without overwriting it.

edited December 2013 in Questions about Code

Hi I have this code where I would like to safe the pdf files but don't overwrite them when I restart the program.

This is what I have.

String pdfname = "LineSight.pdf"; 

void setup(){          
teller += 1;
    pdfname = "LineSight" + teller + ".pdf";
    pdf = (PGraphicsPDF) createGraphics(width, height, PDF, pdfname);
}


void draw(){
Beginrecord()
Endrecord()
}

So mainly what's happening in the setup is what causes it to make different files, but when I restart the program and save again it rewrites the former files.

Answers

  • Answer ✓

    I doubt your code works this way (Beginrecord() instead of beginRecord()), but I suppose it is a mockup just showing the base idea, which is a good idea. :-)

    Well, there is no easy way to keep the information from one run to the next.

    I see two possible ways:

    1. Use File.list() to know which files are already there, and to continue after that (needs to parse the file names). Not obvious.
    2. Easier: Use saveStrings() with an array of one element, to save the value of teller on disk, on a separate file. Then you can use loadStrings() to get it back at the start of your program, and you can increment it.
  • Answer ✓

    maybe put the date and time in the filename so ensure the filenames are unique.

    use yyyymmdd_hhmmss format to preserve the creation order.

Sign In or Register to comment.