简体   繁体   中英

itextpdf : rectangle modify width

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM