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 & HelpPrograms › Continuously saving a PDF with stage content
Page Index Toggle Pages: 1
Continuously saving a PDF with stage content (Read 1525 times)
Continuously saving a PDF with stage content
Aug 18th, 2009, 4:33am
 
Hi

Im drawing little shapes on the stage. I would like to save an image once every x frames.

This is really easy using "saveFrame", however I would like to generate a PDF(vector)  instead so I can scale it up for a 200x140 cm poster.

If I use beginRecord and endRecord I can only do it once, when I write the "buffer" to PDF with endRecord, I can't find a way to generate a new PDF containing everything from when the sketch started to the next time I call beginRecord and endRecord.

Also how will "effects" like Blur and Blend react to being used in a PDF?

Are there any libraries out there that can help or am I just not seeing the answer right in front of me?

Hope some one can help me out here as I just found a place that will print 1 poster fairly cheap, instead of "no we only do a 1000 or more copies".

Thanks in advance Smiley

Re: Continuously saving a PDF with stage content
Reply #1 - Aug 18th, 2009, 5:00am
 
did you read this:

http://processing.org/reference/libraries/pdf/index.html

which gives you a lot more options?
Re: Continuously saving a PDF with stage content
Reply #2 - Aug 18th, 2009, 9:41am
 
Hi

Yeah, I looked through it, it seems I have to record everything from the beginning to a point where endRecord() is called.

I was actually just trying it out, I just sat it to:

if frameCount % 10000 == 0 -> endRecord().

It will run for 20 sec. then complain about memory issues, even though Im on 1024 in the preferences.

It seems bitmap is the only way to get all the blurs, blends and background the way I want it. But that would mean a freakin' huge canvas to get just 150 DPI.

I never really printed anything from processing, am I going about it the wrong way perhaps?
Re: Continuously saving a PDF with stage content
Reply #3 - Aug 18th, 2009, 1:37pm
 
i've only used it twice and then only for single, complete pages. does saving different frames to different pages fit into your scheme? (i'm not sure i understand what you're trying to do). if the output is repeatable you could run it once, save the 1000th frame. run it again, save the 2000th frame etc.

getting past the memory errors might be tricky though.

looking online for places that print large posters i found some that'd do single 60x40 inch prints (smaller than 2m x 1.4m) but they are £85 a time.
Re: Continuously saving a PDF with stage content
Reply #4 - Aug 18th, 2009, 2:05pm
 
this (adapted from the examples) writes the first 50 frames to first page, the 2nd 50 frames (without the first 50) to page 2, etc.

maybe there's a way of merging the pages later.

Quote:

import processing.pdf.*;

PGraphicsPDF pdf;

void setup() {
 size(400, 400);
 pdf = (PGraphicsPDF) createGraphics(width, height, PDF, "pause-resume.pdf");
 beginRecord(pdf);
}

void draw() {
 // Be sure not to call background, otherwise your file
 // will just accumulate lots of mess, only to become invisible
 
 // Draw something good here
 line(mouseX, mouseY, width/2, height/2);

 if (frameCount % 50 == 0) {  
   pdf.nextPage();  // Tell it to go to the next page
 }
}

void keyPressed() {
 if (key == 'q') {
   endRecord();
   exit();
 }
}
Re: Continuously saving a PDF with stage content
Reply #5 - Aug 19th, 2009, 1:05am
 
koogy wrote on Aug 18th, 2009, 2:05pm:
maybe there's a way of merging the pages later.

I saw somewhere a way to do layered PDFs, overlying successive drawings.

And @RickiG, yes, special effects like blur or blends are probably rendered as bitmap (unless PDF supports them like SVG does).
Re: Continuously saving a PDF with stage content
Reply #6 - Aug 20th, 2009, 11:35am
 
PhiLho and Koogy, thanks for the help:)

I found out I was generating thousands of shapes, that did not make it to the actual screen. Removing these cleared up the memory issue (but I guess it will return if I actually meant to generate a +5 million shapes picture again).

I moved all the drawing stuff from the draw method and into the setup method. So when running the sketch, I just get everything generated as fast as processing can keep up. i.e. I moved the draing function from the draw method into a for loop in the setup method.
Code:

import processing.pdf.*;

int totalRuns = 600;

ArrayList spores = new ArrayList();
int amount = 5;
void setup()
{
 size( 200 * 10, 70 * 10 );
 beginRecord(PDF, "everything.pdf");

 for( int i = 0; i < amount; i++ )
 {
   spores.add( new Spore() );
 }
 for( int j = 0; j < totalRuns; j++ )
 {
   for( int k = 0; k < amount; k++ )
   {
Spore s = (Spore)spores.get( k );
s.step();
   }
 }
}

void draw()
{

 endRecord();
 noLoop();
 exit();
}


I need a pdf with only vectors shapes, so that I can scale it up. (the Spores class just draws circles when step() is called).

Using beginRecord() endRecord() this way produces really strange results.

The resulting .pdf seems to be a "recording" of each run of the for loop.
So when opening the finished pdf, which is huge ≈ 30 MB using Preview on the Mac, it sort of plays back the drawing of the layers. Meaining that it displays the first spores, then the next and so on. This happens each time I open the pdf or resize it.

How will I draw a lot of circles and have these saved as vector shapes in a pdf, without it grpwing to some crazy size.

I had a graphics dude helping me, he had never seen a pdf behave that way:)

Cheers!

Ps. I found a place (in Denmark) where they will print 200 x 140 cm on 195 grams/square meter paper for £60, day to day print. If you are interested I will check if they have a .com site.
Re: Continuously saving a PDF with stage content
Reply #7 - Aug 20th, 2009, 11:12pm
 
It is a normal behavior, if you think about this: you store lot of shapes in the PDF, the more you draw, the bigger the file will be. It is vector, it will grow with the size of the objects in it, unlike bitmap whose size is driven by the image size, minus ease of compression depending on complexity of image.
PDF reader have to read and parse all this vector data, and implementors chose to display it progressively, instead of showing a blank window and displaying it all at once after a while (giving feeling of application being stuck!). Hence the impression to replay the sketch...
Re: Continuously saving a PDF with stage content
Reply #8 - Aug 21st, 2009, 4:21am
 
OK, I guess it makes sense as the vector data lies as actual numbers describing the shapes, whereas a bitmap must be rendered in one shot.

Well Im not closer to getting it printed I guess. The 30 MB pdf takes to long to handle. Is there some way to have the pdf not include every shape situated behind other shapes.
I opened the file in illustrator and every single circle, no matter if it is behind or in front, is described via a path.

Any ideas?
Re: Continuously saving a PDF with stage content
Reply #9 - Aug 21st, 2009, 6:07am
 
RickiG wrote on Aug 21st, 2009, 4:21am:
Any ideas

Improve your algorithm Smiley
Easier said than done, I fear...
Re: Continuously saving a PDF with stage content
Reply #10 - Aug 21st, 2009, 7:19am
 
PhiLho that is your answer to everything!  Wink

It is the amount of repetition that makes it look good, so maybe a bitmap approach is better.
Im trying to render a version as a .tif now to see if everything will look OK.

I made a test that was 10000x5000 px, the file ended up at 143MB, but behaved as snappy as any holiday photo when rotated, scaled and zoomed in Preview.
So you are surely right about the amount of vectors causing the lack of speed... lesson learned:) .. need bigger computer!

So if I want to do this as a bitmap that should end up being 55x79" 300DPI (the 200x140cm 300DPI), what kinda resolution am I looking at?

300DPI/72DPI = 4.16 times larger than ... ?
Re: Continuously saving a PDF with stage content
Reply #11 - Aug 21st, 2009, 1:57pm
 
> So if I want to do this as a bitmap that should end up being 55x79" 300DPI

er, 55 inches * 300 dots per inch is just 55 * 300 = 16500
(23700 for 79"). i doubt you'd need 300dpi though, half that should be ok.

300dpi at 3(?) bytes per pixel i make that 1,173,150,000 bytes! about 1.2GB "raw". but compression will bring that down quite a bit. try it and see.
Re: Continuously saving a PDF with stage content
Reply #12 - Aug 23rd, 2009, 12:05pm
 
Cheers Koogy

I called up the printer guy, he almost dared med to send them a .pdf they couldn't handle:)

So I uploaded the original .pdf that had the millions of paths and layer, I'll see tomorrow when it goes to the print if they call me up:)

Page Index Toggle Pages: 1