Loading...
Logo
Processing Forum
Hello,
I'm trying to export PDF while preserving ability to edit text – fonts should not be converted to shapes! According to  docs it should work with createFont() but unfortunately I just can't seem to get it working :-(. Here is very simple example. I've tried it in 2.0b7 and 1.51. I would appreciate any help. Thanx.

Copy code
  1. import processing.pdf.*;
  2. PFont f;

  3. void setup() 
  4. {
  5.   size(200, 200, PDF,"output.pdf");
  6.   background(100);
  7.   f = createFont("FreeSans.ttf",30);
  8.   textFont(f,30); 
  9. }

  10. void draw() {
  11.   fill(0);
  12.   text("Hello", 30, 60);
  13.   exit();
  14. }

Replies(4)

Put this right after the size() call in setup():
Copy code
  1.   textMode(MODEL);

Unfortunately this doesnt work, I've already tried it. In the example above I get error. While in examples that use beginRecord() / endRecord() I don't get error but pdf with font again converted to shapes :-(

Copy code
  1. Exception in thread "Animation Thread" java.lang.RuntimeException: Use textMode(SHAPE) with PDF when loading .ttf and .otf files with createFont().
  2. at processing.pdf.PGraphicsPDF.checkFont(Unknown Source)
  3. at processing.pdf.PGraphicsPDF.textFont(Unknown Source)
  4. at processing.core.PGraphics.textFont(PGraphics.java:3973)
  5. at processing.core.PApplet.textFont(PApplet.java:12137)
  6. at pdf_font_export_test.setup(pdf_font_export_test.java:27)
  7. at processing.core.PApplet.handleDraw(PApplet.java:2117)
  8. at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:193)
  9. at processing.core.PApplet.run(PApplet.java:2020)
  10. at java.lang.Thread.run(Thread.java:662)


It works for me in Processing 1.5.1 and 2.0b7 on WinXP. The problem may be your font.

I can select the text in Adobe Reader and also edit it in Adobe Illustrator CS6.

Adapted Code
Copy code
  1. import processing.pdf.*;
  2.  
  3. void setup() {
  4.   size(200, 200, PDF, "output.pdf");
  5.   textMode(MODEL);
  6.   background(100);
  7.   textFont(createFont("Arial", 30), 30);
  8. }
  9.  
  10. void draw() {
  11.   fill(0);
  12.   text("Hello", 30, 60);
  13.   exit();
  14. }
Thanx Amnon!

You were right, that the problem was in font. I'm sure I've also tested with Arial, but I've probably made some other mistake at the same time.

Other example – one using begin/endRecord had additional problem. It seems like its very sensitive to the order they run in setup. This should be better documented. Order that finaly works for me is this:

/ setup /
1. size()
2. beginRecord()   <--- this had to go before textMode
3. textMode(MODEL)
4. textFont() / createFont()

/ draw /
5. text()
6. endRecord()