1

When I draw an awt component using the graphics context like this:

PdfTemplate template = contentByte.createTemplate(400, 400);
Graphics2D g2d = template.createGraphics(400, 400);

myComponent.paint(g2d);
g2d.dispose();

What units are used here?

When creating the template, I am supposed to use the user units (pt), right? Does it mean that in drawing itself there are used points too?

Let's say there is an image within the awt component that is 100x100 px size. It's drawn by calling g2d.drawImage(image). But if the units are points, the image will be bigger than it should be.

Jan Krakora
  • 2,500
  • 3
  • 25
  • 52

1 Answers1

1

By default a user unit corresponds with a typographic point, but you can change this in the PdfWriter settings (you can change it from 1 to 75000).

If you have an image of 100x100 px, then iText will interpret this as 100x100 pt image. We know that's not always correct, but a px value has no real meaning without a resolution value.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • So when I need to draw my component 1:1 in awt and in pdf, what is the propper way to do that? Note I can't change the PdfWriter settings. – Jan Krakora Dec 11 '12 at 12:35
  • I usually create the PdfTemplate in points, and I then resize the PdfTemplate, for instance by wrapping it in an Image object and scaling it with a percentage that is calculated based on the values 72 pt per inch and the resolution expresssed in dots per inch. – Bruno Lowagie Dec 11 '12 at 16:30