We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Multipage PDF does not work anymore
Page Index Toggle Pages: 1
Multipage PDF does not work anymore (Read 438 times)
Multipage PDF does not work anymore
Jan 18th, 2009, 7:35pm
 
I need to render PDFs with many pages. I do remember that I did this a couple of times and never had problems with that. However, today i tried to get it working and failed.
I then checked the example from the docs, and this did not work either. It only creates a first page and then a second one, which is blank, that's it.
I have no Idea why this could have stopped working.
Is anyone able to do this ?


from the docs (http://processing.org/reference/libraries/pdf/index.html):

Multiple Pages (No Screen Display)
It's possible to write every frame as a new page in the PDF document. This example creates a 100 page document:

import processing.pdf.*;

void setup() {
 size(400, 400, PDF, "filename.pdf");
}

void draw() {
 // Draw something good here
 line(0, 0, frameCount * 4, height);
   
 PGraphicsPDF pdf = (PGraphicsPDF) g;  // Get the renderer
 pdf.nextPage();  // Tell it to go to the next page

 // When finished drawing, quit and save the file
 if (frameCount == 100) {
   exit();
 }
}

does not work.

I do have a workaround by using PGraphicsPDF and calling the constructor with an absolute path etc, but this seems overhead. It would be nice if it would work as simple as in the docs.
Re: Multipage PDF does not work anymore
Reply #1 - Jan 19th, 2009, 3:14am
 
edit:
I have no workaround. Everything I tried failed.
I am not able to create a PDF with more than two pages, no matter what I try.

Is anybody able to render more than two pages into one PDF ?
Re: Multipage PDF does not work anymore
Reply #2 - Jan 19th, 2009, 1:00pm
 
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.
Re: Multipage PDF does not work anymore
Reply #3 - Jan 21st, 2009, 12:10am
 
yesss, this works.
awesome, thanks a lot for your help. :)

i reported this as a bug aka something that needs an update.
Re: Multipage PDF does not work anymore
Reply #4 - Jan 21st, 2009, 3:54am
 
wow, this method seems even waaaay faster than what i've seen so far. yay ;)
really amazing speeed.
Page Index Toggle Pages: 1