save pdf from library
in
Library and Tool Development
•
1 year ago
Sometimes i have nice unwanted progress (serendipity).
The fastest for me is making a screenshot but sometimes i like vectors, it's only a bit more work to get a pdf instead of using the screenshot shortcut on my mac.
I know it's not much code to get a pdf from processing but i want it to make it even a litle bit more easier for me.
I think i'm pretty close, i only can't find the file :S
processing:
- import processing.pdf.*;
- import doeke.methods.*;
- PDFSaver pdfSaver;
- void setup() {
- pdfSaver = new PDFSaver(this);
- }
- void draw() {
- background(255);
- for(int i = 0; i < 40; i++) {
- ellipse(random(width), random(height), random(50), random(50));
- }
- }
- void keyPressed() {
- pdfSaver.save();
- }
The library:
- import processing.core.PApplet;
- /*
- * Save mode!! name, date, counter etc.
- *
- *
- */
- public class PDFSaver {
- private PApplet p;
- private boolean save = false;
- private String fileSeparator;
- public PDFSaver(PApplet p) {
- this.p = p;
- fileSeparator = System.getProperty("file.separator");
- p.registerPre(this);
- p.registerDraw(this);
- }
- public void save() {
- save = true;
- }
- public void pre() {
- if(save) {
- // i checked, pre does run
- // only in this state a println is not possible.
- System.out.println("start save");
- p.beginRecord(PApplet.PDF, p.sketchPath+fileSeparator+"test.pdf");
- }
- }
- public void draw() {
- if(save) {
- System.out.println("end save");
- System.out.println(p.sketchPath+fileSeparator+"test.pdf");
- p.endRecord();
- save = false;
- }
- }
- }
1