
Is it possible to modify width of existing rectangle ?
I have :
@Override
public void onGenericTag(PdfWriter writer, Document document, Rectangle rect, String text){
Rectangle rectangle = new Rectangle(rect);
//something like that :
rectangle.setWidth(400f);
}
解决方案
You can (and should) not use a method called setWidth(). Whatever that method would do would be very ambiguous.
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.
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.
这篇博客探讨了在使用iText库时,如何避免使用Ambiguous的setWidth()方法来设置矩形宽度。作者建议通过setLeft()和setRight()明确调整边界,以消除方向不确定性。
1041

被折叠的 条评论
为什么被折叠?



