Hi, I'm new to processing, and I'm running v1.1 on OSX10.5. I've run into a snag trying to output text to a PDF file and I'm looking for some help. Things seem to work if I use the size() method to write to PDF. For example, both of these code sections work great:
Code:
import processing.pdf.*;
size(512, 512, PDF, "test.pdf");
background(255);
PFont arial = createFont("Arial", 48);
textFont(arial);
fill(0);
text("Hello!",100,50);
exit();
Code:
import processing.pdf.*;
PFont font;
void setup() {
size(512,512,PDF,"test.pdf");
background(255);
font = createFont("Arial",48);
textFont(font);
fill(0);
noLoop();
}
void draw() {
text("Hello!",200,200);
exit();
}
But if I move to using the beginRecord/endRecord solution to capture a single frame I get an export error message. The code that's producing the error is:
Code:
import processing.pdf.*;
boolean bool;
PFont font;
void setup() {
size(512,512,PDF,"test.pdf");
background(255);
bool = true;
font = createFont("Arial",48);
textFont(font);
fill(0);
}
void draw() {
if (bool) {
beginRecord(PDF, "test.pdf");
}
text("Hello!",200,200);
if (bool) {
endRecord();
bool = false;
}
}
The error trace that this produces for me is:
Code:
alias for Arial = Arial
alias for SansSerif = null
Use PGraphicsPDF.listFonts() to get a list of fonts that can be used with PDF.
processing.app.debug.RunnerException: RuntimeException: The font “SansSerif” cannot be used with PDF Export.
at processing.app.Sketch.placeException(Sketch.java:1565)
at processing.app.debug.Runner.findException(Runner.java:568)
at processing.app.debug.Runner.reportException(Runner.java:543)
at processing.app.debug.Runner.exception(Runner.java:498)
at processing.app.debug.EventThread.exceptionEvent(EventThread.java:367)
at processing.app.debug.EventThread.handleEvent(EventThread.java:255)
at processing.app.debug.EventThread.run(EventThread.java:89)
Exception in thread "Animation Thread" java.lang.RuntimeException: The font “SansSerif” cannot be used with PDF Export.
at processing.pdf.PGraphicsPDF.textLineImpl(PGraphicsPDF.java:414)
at processing.core.PGraphics.textLineAlignImpl(PGraphics.java:3509)
at processing.core.PGraphics.text(PGraphics.java:3208)
at processing.core.PGraphics.text(PGraphics.java:3163)
at processing.core.PApplet.text(PApplet.java:8632)
at sketch_mar19a.draw(sketch_mar19a.java:37)
at processing.core.PApplet.handleDraw(PApplet.java:1594)
at processing.core.PApplet.run(PApplet.java:1496)
at java.lang.Thread.run(Thread.java:613)
So it looks like using begin/endRecord is expecting the SansSerif font, rather than Arial, and gets confused. I'm probably doing something wrong or missing something. Any help would be great!
Thanks!
--mah