Created
June 15, 2015 12:20
-
-
Save 3846masa/43490a217700ba4ece5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
class EmbedPdeInPdf { | |
PApplet parent; | |
String filename; | |
EmbedPdeInPdf(PApplet _parent) { | |
parent = _parent; | |
} | |
void beginRecord(String mode, String filename) { | |
parent.beginRecord(mode, filename); | |
this.filename = filename; | |
} | |
void endRecord() { | |
parent.endRecord(); | |
String[] pdefiles = new File(sketchPath).list(); | |
byte[] pdf = loadBytes(this.filename); | |
ArrayList<Byte> export = new ArrayList<Byte>(); | |
export.addAll(Arrays.asList(new Byte[] {0x2F, 0x2A, 0x0A})); | |
for (byte b : pdf) { | |
export.add(b); | |
} | |
export.addAll(Arrays.asList(new Byte[] {0x0A, 0x2A, 0x2F, 0x0A})); | |
for (String pdefile : pdefiles) { | |
if (pdefile.indexOf(".pde") != pdefile.length() - ".pde".length()) { | |
continue; | |
} | |
byte[] pde = loadBytes(pdefile); | |
for (byte b : pde) { | |
export.add(b); | |
} | |
export.add((byte)0x0A); | |
} | |
byte[] exportArray = new byte[export.size()]; | |
for (int i = 0; i < exportArray.length; i++) { | |
Byte b = export.get(i); | |
exportArray[i] = b.byteValue(); | |
} | |
saveBytes(this.filename, exportArray); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.pdf.*; | |
EmbedPdeInPdf pdf; | |
void setup() { | |
size(400, 400); | |
noLoop(); | |
pdf = new EmbedPdeInPdf(this); | |
pdf.beginRecord(PDF, "export.pdf"); | |
} | |
void draw() { | |
background(128); | |
ellipse(width/2, height/2, width/2, height/2); | |
pdf.endRecord(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment