pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shawn A <mrcrim...@gmail.com>
Subject Re: DrawString with TrueType embedded fonts.
Date Sat, 14 Feb 2009 21:19:59 GMT
> Hmmm, I still try to understand what you're trying to do? What is the
> goal of your implementation? Do you try to put some text on a page and
> convert this page to a png image?
> If I am right I suggest to do it like this:

What I am trying to accomplish right now is just use the embedded truetype font
and render some text to an image. Are you talking about the previous
time we talked
when you mentioned implementation?

> - create a PDDocument
> - add a PDPage to the document
> - add the needed fonts to the document wiht PDTrueTypeFont.loadTTF
> - use PDPageContentStream to add some text with beginText, drawString,
> endText etc.
> - use PDPage.convertToImage to create the image

I could do that, except that the TTF's I have are still inside of an
existing PDF, so I
need to add it another way. I am also not sure if you are mentioning
this in the context
of the last time we spoke or not?

Thank you for your help.

On Sat, Feb 14, 2009 at 8:08 PM, Andreas Lehmkühler <andreas@lehmi.de> wrote:
>
> > 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?
> Hmmm, I still try to understand what you're trying to do? What is the
> goal of your implementation? Do you try to put some text on a page and
> convert this page to a png image?
> If I am right I suggest to do it like this:
>
> - create a PDDocument
> - add a PDPage to the document
> - add the needed fonts to the document wiht PDTrueTypeFont.loadTTF
> - use PDPageContentStream to add some text with beginText, drawString,
> endText etc.
> - use PDPage.convertToImage to create the image
>
>
> > This is with pdfbox 0.7.4.
> There are some improvements concerning font-handling in later 0.7.4 versions
> and in the upcoming version 0.8.
>
>
> HTH
> Andreas
>

Mime
View raw message