问题
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