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 › Beginner needs help with Processing and text + pdf
Page Index Toggle Pages: 1
Beginner needs help with Processing and text + pdf (Read 620 times)
Beginner needs help with Processing and text + pdf
Nov 18th, 2009, 3:55am
 
Hello,
I am very new to processing and find it of great interest.
However I have a problem rendering text in a pdf file. The text just does not render.

Here is my program for a binomial tree:
Code:
import processing.pdf.*;

int unit = 80;
int steps = 5;

size(100*steps,12*unit);

PFont font = loadFont("ArialMT-48.vlw");

PGraphicsPDF pdf;
pdf= (PGraphicsPDF)beginRecord(PDF, "binomial-tree.pdf");
beginRecord(pdf);

//quad(0, height/2, unit, height/2 - unit, unit*2, height/2, unit, height/2 + unit);

String spotPriceStr = "S";//these will never render
String optionPriceStr = "f";//these will never render

strokeWeight(2.0);

//Thin lines
for(int outer = steps; outer>0; outer--){
 pushMatrix();
 for(int inner = 0; inner<outer; inner++){
   line(0+(steps-outer)*unit, height/2 +(steps-outer)*unit, unit +(steps-outer)*unit, height/2 - unit +(steps-outer)*unit);
   translate(unit,-unit);
}
 popMatrix();
 
 pushMatrix();
 for(int inner = 0; inner<outer; inner++){
   line(0+(steps-outer)*unit, height/2 +(steps-outer)*unit, unit +(steps-outer)*unit, height/2 + unit +(steps-outer)*unit);
   translate(unit,-unit);
 }
 popMatrix();
}

//Thick points
for(int outer = steps; outer>=0; outer--){
 pushMatrix();
 for(int inner = 0; inner<=outer; inner++){
   pushStyle();
   stroke(#ff0000);
   strokeWeight(10.0);
   point(0+(steps-outer)*unit, height/2 + (steps-outer)*unit);
   strokeWeight(3.0);
   textFont(font, 32);
   fill(#000000);
   //textLeading(10);
   text(optionPriceStr, 0+(steps-outer)*unit, height/2 + (steps-outer)*unit);
   translate(unit, -unit);
   popStyle();
 }
 popMatrix();
}

endRecord();


Can anyone please enlighten me..

Julien.
Re: Beginner needs help with Processing and text + pdf
Reply #1 - Nov 18th, 2009, 4:36am
 
For what it is worth, I replaced the loadFont with createFont:
PFont font = createFont("Arial", 48);
because I was too lazy to save the sketch and create the font...
And it worked.
Double-check the PDF reference page, there are several paragraphs about rendering text and fonts in PDF.
Re: Beginner needs help with Processing and text + pdf
Reply #2 - Nov 18th, 2009, 9:02am
 
Thanks.
Sorted!
J.
Page Index Toggle Pages: 1