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.
Page Index Toggle Pages: 1
PDF for Dummies (Read 3755 times)
PDF for Dummies
Apr 25th, 2006, 9:40pm
 
I tried running some suggestion of what was referred to here but I can't figure out how to get it to work.

The following code doesn't work, it doesn't generate an applet window but it generates a blank pdf that Acrobat refuses to deal with because it's being worked on. There's nothing for the mousePress event to be focused on:
Code:

import processing.pdf.*;
void setup() {
size(400, 400, pdf, "filename.pdf");
}
void draw() {
line(0,0,height,width);
}
void mousePressed() {
exit();
}

I've looked in the revision notes and I can't find any illumination. It's clear that it's quite obvious to everyone else what they're supposed to do but I can't even get a "hello world" applet for pdf running.

Could someone show me the bare minimum code to get this thing to work please?
Re: PDF for Dummies
Reply #1 - Apr 25th, 2006, 10:13pm
 
as of more recent releases, pdf sketches don't open a window, so mousePressed isn't gonna work. try this:

Code:
import processing.pdf.*; 

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

void draw() {
line(0,0,height,width);
exit();
}
Re: PDF for Dummies
Reply #2 - Apr 25th, 2006, 10:55pm
 
This works really well Smiley, but my Illustrator cs2 beach balls me like crazy on OSX, but I put that down to RAM and Adobe.

Is it possible to exclude elements from the draw cycle?
I'm recording across several frames and have some GUI stuff I'd prefer not to save as part of the PDF. I can work round easily enough, but perhaps there's already a way?
Re: PDF for Dummies
Reply #3 - Apr 25th, 2006, 11:17pm
 
yep, that's what beginRecord/endRecord are for.
Re: PDF for Dummies
Reply #4 - Apr 26th, 2006, 9:20am
 
But what if I'm building a PDF that takes a shot every (n)th frame, but part of the interaction requires a GUI element to be on the screen. How would I omit the GUI stuff from the recording without being forced to start a new file each frame?

Or, how could I keep drawing to the screen, but only record every (n)th frame, as it would appear that once recording has started all drawing is saved, and not just the bits you want.

Sorry if I'm missing something very obvious, it wouldn't be the first time!
Re: PDF for Dummies
Reply #5 - Apr 26th, 2006, 10:52am
 
That's what beginRecord/endRecord are for.

You create your sketch with size(400,400); withotu the PDF stuff, then when you want to record a certain frame you do:

Code:
beginRecord(PDF, "frame-####.pdf");

... awesome drawing stuff ...

endRecord();
Re: PDF for Dummies
Reply #6 - Apr 26th, 2006, 11:38am
 
Thanks guys. Cheesy
Re: PDF for Dummies
Reply #7 - Apr 26th, 2006, 11:54am
 
Quote:
That's what beginRecord/endRecord are for.


Thanks, John. Yes, that's what I've been doing, however...

As a sequence of interactions over a number of frames, rather than them all being part of the same PDF, they'd be ####.pdf sequential files. (I seem to remember an experiment yesterday, where beginRecord and endRecord (n)frames later produces a single file, not a #### sequence).

Anyhow it's not really an issue to worry about, it's just that I'm not at my machine so can't test this out, so sorry for any misunderstanding. Just curious!
Re: PDF for Dummies
Reply #8 - Apr 26th, 2006, 1:35pm
 
to make it all part of the same file, you create the pdf in setup, and then pass that to beginRecord inside draw. this is the second example on beginRecord in revisions.txt.

Code:
PGraphics pdf;

void setup() {
 // setup stuff..
 pdf = createGraphics(PDF, "blah.pdf");
}

void draw() {
 // draw gui things not in the pdf

 beginRecord(pdf);
 // draw pdf things
 endRecord();
}
Re: PDF for Dummies
Reply #9 - Apr 26th, 2006, 3:53pm
 
Thanks for the explanation. The penny has well and truly dropped.
Re: PDF for Dummies
Reply #10 - Jun 12th, 2006, 1:17am
 
I'm guessing the answer is going to be no (because I've tried already), but is there a way I can get my 3D line drawing to output a flat PDF?

PDF doesn't work with P3D commands as I've gathered, but is there any scope for this? Or is it some crazy voodoo I should get off my bum and learn?
Re: PDF for Dummies
Reply #11 - Jun 12th, 2006, 12:29pm
 
PDF can do 3D if you use the beginRaw() / endRaw() methods instead of beginRecord() / endRecord(). It will then support lines and polygons, but not points. Also, it won't do Z-buffering, so intersecting objects will be rendered in the order they are drawn.

See this example:

PDF for complex 3D output
Re: PDF for Dummies
Reply #12 - Jun 12th, 2006, 6:29pm
 
Code:

void keyPressed(){
PGraphicsPDF pdf=(PGraphicsPDF)beginRaw(PDF, "myPdf.pdf");
//background() command is ignored
pdf.fill(255);
pdf.noStroke();
pdf.rect(0,0, width,height);

/*
Insert Glory
*/

endRaw();
}

Got it, thank you very much.
Page Index Toggle Pages: 1