itextpdf:矩形修改宽度 [英] itextpdf : rectangle modify width

查看:851
本文介绍了itextpdf:矩形修改宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以修改现有矩形的宽度?

Is it possible to modify width of existing rectangle ?

我有:

@Override
public void onGenericTag(PdfWriter writer, Document document, Rectangle rect, String text){
Rectangle rectangle = new Rectangle(rect);
//something like that :
rectangle.setWidth(400f);
}


推荐答案

你可以(而且应该)不要使用名为 setWidth()的方法。无论这种方法做什么都会非常模糊。

You can (and should) not use a method called setWidth(). Whatever that method would do would be very ambiguous.

假设你有一个左下角的矩形 x 坐标等于36,右上角 x 坐标等于559.(我没有随机选择这些数字:这些是默认A4页面内的默认边距使用iText。)现在当你改变这样一个矩形的宽度时:你的意思是将矩形向左,向右,或两者都延伸?我希望这个例子表明,使用 setWidth()方法是没有意义的。

Suppose that you would have a rectangle with lower-left x coordinate equal to 36 and with upper-right x coordinate equal to 559. (I didn't choose these numbers at random: those are the default margins inside the default A4 page when using iText.) Now when you change the width of such a rectangle: do you mean to extend the rectangle to the left, to the right, or both? I hope this example shows that having a setWidth() method doesn't make sense.

相反,你应该更改 x setLeft() setRight() c>矩形的左坐标或右坐标的值,您自动更改宽度,并且不会混淆您更改宽度的方向。

Instead, you should use setLeft() or setRight() when you change the x value of the left or right coordinate of the rectangle, you automatically change the width and there can be no confusion about the direction in which you're changing the width.

这篇关于itextpdf:矩形修改宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆