Export PDF with selectable text

Hi All,

First time posting. Having trouble with this problem in the 2.0 version. It seems some one was able to solve this in the 1.5 version. http://forum.processing.org/one/topic/pdf-font-export-preserving-ability-to-edit-text.html However when I tried it in 2.0, I still have the textMode(SHAPE) with "Arial" when exporting to PDF error.

Any ideas? Here's the code

import processing.pdf.*;

void setup() {


  size(200, 200, PDF, "output.pdf");


  beginRecord(PDF, "test.pdf");


  textMode(MODEL);


  background(100);


  textFont(createFont("IdealSans-Book-Pro.otf", 30), 30);


}





void draw() {


  fill(0);


  text("Hello", 30, 60);


  endRecord();


  exit();


}

Thanks

Tagged:

Answers

  • Looks like you are having the same issue as the post you reference.

    I get the error to use textMode(SHAPE) when loading .ttf or .otf fonts.

    If you change to 'Arial' as in the example, it seems to work as expected. It's unclear why Arial works, on my system it is also a TTF. Baskerville seems to work too, not sure why.

    Hope this helps! ak

  • Sorry, just saw your last sentence about trying Arial. Very strange, what system are you on? what type of font file is Arial? can you go through a few fonts and find any that do work?

  • I couldn't find anything on this and spent a lot of time blindly plugging textMode(MODEL) into other PDF examples on the forum. Looks like you need to use PFont in the sketch.

    Here is some working code for anyone who might still need a solution:

        import processing.pdf.*;
    
        void setup() {
            size(400, 400, PDF, "filename.pdf");
            textMode(MODEL);
        }
    
        void draw()    {
            PFont f;
            f = createFont("Times New Roman",    40);
            textFont(f, 40);
            translate(width/2, height/2);
            fill(0);
            text("test",0,0);
            exit();
        }
    
  • @jakejake -- thank you for sharing this example solution.

Sign In or Register to comment.