pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shawn A <mrcrim...@gmail.com>
Subject DrawString with TrueType embedded fonts.
Date Sat, 14 Feb 2009 04:18:13 GMT
When I use drawString on a PDFont object loaded from an embedded TTF,
the resulting string shows a different font. Here is my code:

PDDocument pdf = PDDocument.load(is);

BufferedImage img = new BufferedImage(160,160,BufferedImage.TYPE_INT_RGB);
java.util.Map m =
((PDPage)pdf.getDocumentCatalog().getAllPages().get(0)).getResources().getFonts();
int x =0;
for(Object key : m.keySet())
{
Object val = m.get(key);
PDFont f = (PDFont)val;
                       System.out.println(f.getBaseFont());
f.drawString("AXIL@UAXICUIUASD",img.getGraphics(),
(float)12.0,
(float)1.0,
(float)1.0,
(float)50.0,
(float)100.0 + x);
x+=10;
}
javax.imageio.ImageIO.write(img,"bmp",new
java.io.FileOutputStream("/tmp/out.bmp"));
pdf.close();

The font families that are rendered in a sample document are:
Arial-BoldMT
TimesNewRomanPS-BoldMT
ArialMT
TimesNewRomanPSMT

And here is the resulting image:
http://i39.tinypic.com/o8xr8w.png

Also, these embedded fonts are bad, I know that, so that the letters I chose
to render should run together and become illegible.

Is it something wrong I am doing; or is drawString ignoring the TrueType
fonts?

This is with pdfbox 0.7.4.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message