开发者

Itext and PngImage

开发者 https://www.devze.com 2023-04-03 03:25 出处:网络
I have a java application which usesitext for generating reports. I have to include a logo which is in a resolution of 150dpi.

I have a java application which usesitext for generating reports. I have to include a logo which is in a resolution of 150dpi. The code I uwrote is the following:

final float logoWidth = 368;
final float logoHeigth = 182;
float x = PageSize.A4.getWidth() - (16 * millimeters) - logoWidth;
float y = PageSize.A4.getHeight() - logoHeigth;    

final 开发者_运维百科InputStream idLogo = getClass().getResourceAsStream("/logos/ID_Module_150dpi_layoutgroesse.png");

Image logoTop = PngImage.getImage(idLogo);
logoTop.setAbsolutePosition(x, y);

The problem is that the logo is added at the right position but the size is not correct. It is twice the height and twice the width. What am I doing wrong here?

Thanks in advance!


Have you tried scaleToFit()

Image logoTop = PngImage.getImage(idLogo);
logoTop.scaleToFit(x, y);

And then positioning it, personally I use scaleToFit() combined with tables in iText to position

0

精彩评论

暂无评论...
验证码 换一张
取 消