当我改变宽度时,高度在itext中改变

问题描述 投票:0回答:1

当我改变宽度时,画布的高度会发生变化。

ImageData data = ImageDataFactory.create("C:\\800px-Cubicpoly.png");

当我指定:

data.setWidth(100);
data.setHeight(180*2.834646f);

事实证明:enter image description here

当我指定:

data.setWidth(600);
data.setHeight(180*2.834646f);

事实证明:enter image description here

我没有触及高度,为什么会改变?

doc.add(new Image(data).setPadding(0).setMargins(0,0,0,0));

原始的img(800x800):enter image description here

java itext7
1个回答
0
投票

您没有附加整个代码,但我认为您使用的是默认页面大小(A4)。考虑到A4页面的宽度是595 pt(考虑边距,它会更小)并且您将图像宽度设置为600pt,我假设您在处理代码时得到以下日志消息:com.itextpdf.layout.renderer.RootRenderer WARN Element does not fit current area.

缺乏区域是您以意想不到的方式处理图像的原因。为了确保您的安全,请将文档的大小更改为更大的文档(例如,A3),并确保按预期处理所有内容。

那么当无法在设定区域处理图像时,iText通常会做什么呢? iText将其自动调整,尽量占用尽可能多的位置,但要保留图像的比例。你说图像的高度正在变化:但宽度也是如此。

© www.soinside.com 2019 - 2024. All rights reserved.