You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Eric Chow <er...@gmail.com> on 2010/11/25 03:00:40 UTC

Use external TrueType font in PDFBox-1.3.1?

Hello,

In my PDF, I am using some windows TrueType Font.
For example, a true type font file "kaiu.ttf", how can I load this font file
for converting the pdf pages to image?

Would you please to teach me? Or would you please to show me a simple
example?

Furthermore, how can I change the original v1.3.1 source codes for this?

In the version 1.1, I add some codes in the
org.apache.pdfbox.pdmodel.font.PDType1Font.java as following:


public void drawString( String string, Graphics g, float fontSize,
            AffineTransform at, float x, float y ) throws IOException


.....



          // line 241
           try {
                  // loads the external TrueType Font
                  Font customerFont = FontLoader.loadFont(baseFont);

                  if (customerFont != null) {
                     awtFont = customerFont;
                  }
                } catch(Exception ex) {

                }

                if (awtFont == null) {
                  // we can't find anything, so we have to use the standard
font
                    awtFont = FontManager.getStandardFont();
                }

                log.info("Using font "+awtFont.getName()+ " instead");


}





But in the v1.3.1, I added these codes in the PDType1Font.java, it doesn't
work any more.
Would you please to teach me?

Best regards,
Eric