You are right. I played a bit with the sample code, using:
Code:import processing.pdf.*;
PFont f;
int pageCount = 10;
int prevX;
void setup() {
size(400, 400, PDF, "filename.pdf");
f = createFont("Arial", 72);
prevX = width/2;
}
void draw() {
println("Making page " + frameCount);
background(255);
fill(#005500);
stroke(#000055);
strokeWeight(5);
textFont(f, 72);
int newX = int(random(0, width));
// Draw something good here
line(prevX, 0, newX, height);
prevX = newX;
text("Page " + frameCount, 100, 200);
// When finished drawing, quit and save the file
if (frameCount >= 10) {
println("Done");
exit();
} else {
PGraphicsPDF pdf = (PGraphicsPDF) g; // Get the renderer
pdf.nextPage(); // Tell it to go to the next page
}
}
In 0135, it works fine. In 0154 and 1.0.1, I get only the last page. And it seems a bit slower.
In the
list of revisions, I see: "
ABOUT REV 0142 - 16 June 2008 - Update iText in PDF library to 2.1.2u"
That's the only PDF related change I see there.
Ah! I have read the reference page, and I tried to mix two techniques: createGraphics and nextPage:
Code:import processing.pdf.*;
PFont f;
int pageCount = 10;
int prevX;
PGraphics pdf;
void setup() {
size(400, 400);
f = createFont("Arial", 72);
prevX = width/2;
pdf = createGraphics(400, 400, PDF, "multipage.pdf");
pdf.beginDraw();
}
void draw() {
println("Making page " + frameCount);
pdf.background(255);
pdf.fill(#005500);
pdf.stroke(#000055);
pdf.strokeWeight(5);
pdf.textFont(f, 72);
int newX = int(random(0, width));
// Draw something good here
pdf.line(prevX, 0, newX, height);
prevX = newX;
pdf.text("Page " + frameCount, 100, 200);
// When finished drawing, quit and save the file
if (frameCount >= 10) {
println("Done");
pdf.dispose();
pdf.endDraw();
exit();
} else {
PGraphicsPDF pdfg = (PGraphicsPDF) pdf; // Get the renderer
pdfg.nextPage(); // Tell it to go to the next page
}
}
It worked! And it is fast!
Now, I suggest you fill in a bug report in the Contribute section of the site: either the doc should be updated, or, more likely, the bug should be fixed.