itextpdf : rectangle modify width

流过昼夜 提交于 2019-12-12 03:46:12

问题


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);
}

回答1:


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.



来源:https://stackoverflow.com/questions/32869808/itextpdf-rectangle-modify-width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!