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 createGraphics (Read 1136 times)
pdf createGraphics
Dec 12th, 2006, 1:29pm
 
Hi. I'm having problems with this code from the PDF reference:

Code:
import processing.pdf.*;

PGraphicsPDF pdf = createGraphics(300, 300, PDF, "output.pdf");
pdf.background(128, 0, 0);
pdf.line(50, 50, 250, 250);
pdf.dispose();


I suppose I could poke my nose into what’s going on under the hood, but I'm a) feeling a little lazy today, and b) sort of tight on how much time I can take out on this.

Following Marius Watz' export example, I tried to force it's hand with this addition:

Code:
PGraphicsPDF pdf = (PGraphicsPDF)createGraphics(300, 300, PDF, "output.pdf"); 



Which makes it happier, since it gives me back an instantiated object, but then I get a nullpointer exception on the pdf.background() method and all other methods (even pdf.line()).

beginExport() works fine, but I want to export directly to PDF, no writing to the screen, which the above method is supposed to cover.

Any ideas?
Re: pdf createGraphics
Reply #1 - Dec 12th, 2006, 2:03pm
 
I think you need pdf.beginDraw(); before you do any drawing to the pdf.
Re: pdf createGraphics
Reply #2 - Dec 12th, 2006, 2:10pm
 
I tried various arrangements of the commands. This was the first I managed to get to work:
Code:

import processing.pdf.*;
PGraphicsPDF pdf;

void setup(){
size(200,200,P3D);
pdf = (PGraphicsPDF)createGraphics(300, 300, PDF, "output.pdf");
beginRaw(pdf);
pdf.fill(255);
pdf.stroke(10);
pdf.line(0,0,200,200);
endRaw();
}

It didn't like actions being performed on "pdf" before beginRaw(pdf) and it doesn't like not using P3D either. It does however not draw to the screen and create a pdf separate from the stage.
Re: pdf createGraphics
Reply #3 - Dec 12th, 2006, 2:44pm
 
there are two errors in the reference. first is that it needs to be enclosed in pdf.begin/endDraw, the other is casting the pdf object.

this is the correct code and i've just tested that it works ok:

Code:
import processing.pdf.*;

PGraphics pdf = createGraphics(300, 300, PDF, "output.pdf");
pdf.beginDraw();
pdf.background(128, 0, 0);
pdf.line(50, 50, 250, 250);
pdf.dispose();
pdf.endDraw();


i'll update the reference for the next release.
Re: pdf createGraphics
Reply #4 - Dec 12th, 2006, 3:09pm
 
Great. Works on my end. That sure was fast. I should have waited. Now I have to remove all that work-around code Wink
Page Index Toggle Pages: 1