Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : No font in exported PDF

$
0
0
Yeah, the PDF Export library page doesn't tell you a whole lot. It is mostly very confusing. The code examples are somewhat inconsitent and there is no real reference material. Just examples. I set out to try the example code to see which example might work. I modified the first one and, to my surprise, it worked.

  1. import processing.pdf.*;

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

    void draw()    {
        // Draw    something    good here

        PFont    f;
        textAlign(CENTER);
        f    =    createFont("Times New Roman",    40);
        textFont(f,    40);
        background(255);
        String message = "Times New Roman text along a curve";
       
        // The radius of a circle
        float r = 100;
        // Start in    the    center and draw    the    circle
        translate(width    /    2, height    /    2);
        noFill();
        stroke(0);
        ellipse(0, 0,    r*2, r*2);

        // We    must keep    track    of our position    along    the    curve
        float    arclength    =    0;

        // For every box
        for    (int i = 0;    i    <    message.length();    i++)
        {
            // Instead of    a    constant width,    we check the width of    each character.
            char currentChar = message.charAt(i);
            float    w    =    textWidth(currentChar);

            // Each    box    is centered    so we    move half    the    width
            arclength    += w/2;
            // Angle in    radians    is the arclength divided by    the    radius
            // Starting    on the left    side of    the    circle by    adding PI
            float    theta    =    PI + arclength / r;         

            pushMatrix();
            // Polar to    cartesian    coordinate conversion
            translate(r*cos(theta),    r*sin(theta));
            // Rotate    the    box
            rotate(theta+PI/2);    // rotation    is offset    by 90    degrees
            // Display the character
            fill(0);
            text(currentChar,0,0);
            popMatrix();
            // Move    halfway    again
            arclength    += w/2;
        }

        // Exit    the    program   
        println("Finished.");
        exit();
    }

Sort of.



I do get the selected font to display in the PDF now but it is still not embedded. I printed the output PDF to another PDF using NitroPDF and it embedded the font but it was the wrong font. So if I send it to say, a service provider, it may not print correctly. I tried different fonts but NitroPDF always embeds TrueType CourierNew, which I believe is the default font I was getting before. So problem still not entirely solved. I wonder how Acrobat is getting the font information if it is not embedded.

Viewing all articles
Browse latest Browse all 1768

Trending Articles