Package org.apache.pdfbox.pdmodel.common
Class PDRectangle
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.common.PDRectangle
-
- All Implemented Interfaces:
COSObjectable
public class PDRectangle extends java.lang.Object implements COSObjectable
A rectangle in a PDF document.
-
-
Field Summary
Fields Modifier and Type Field Description static PDRectangle
A0
A rectangle the size of A0 Paper.static PDRectangle
A1
A rectangle the size of A1 Paper.static PDRectangle
A2
A rectangle the size of A2 Paper.static PDRectangle
A3
A rectangle the size of A3 Paper.static PDRectangle
A4
A rectangle the size of A4 Paper.static PDRectangle
A5
A rectangle the size of A5 Paper.static PDRectangle
A6
A rectangle the size of A6 Paper.static PDRectangle
LEGAL
A rectangle the size of U.S.static PDRectangle
LETTER
A rectangle the size of U.S.private static float
POINTS_PER_INCH
user space units per inchprivate static float
POINTS_PER_MM
user space units per millimeterprivate COSArray
rectArray
-
Constructor Summary
Constructors Constructor Description PDRectangle()
Constructor.PDRectangle(float width, float height)
Constructor.PDRectangle(float x, float y, float width, float height)
Constructor.PDRectangle(BoundingBox box)
Constructor.PDRectangle(COSArray array)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(float x, float y)
Method to determine if the x/y point is inside this rectangle.PDRectangle
createRetranslatedRectangle()
This will create a translated rectangle based off of this rectangle, such that the new rectangle retains the same dimensions(height/width), but the lower left x,y values are zero.COSArray
getCOSArray()
This will get the underlying array for this rectangle.COSBase
getCOSObject()
Convert this standard java object to a COS object.float
getHeight()
This will get the height of this rectangle as calculated by upperRightY - lowerLeftY.float
getLowerLeftX()
This will get the lower left x coordinate.float
getLowerLeftY()
This will get the lower left y coordinate.float
getUpperRightX()
This will get the upper right x coordinate.float
getUpperRightY()
This will get the upper right y coordinate.float
getWidth()
This will get the width of this rectangle as calculated by upperRightX - lowerLeftX.void
setLowerLeftX(float value)
This will set the lower left x coordinate.void
setLowerLeftY(float value)
This will set the lower left y coordinate.void
setUpperRightX(float value)
This will set the upper right x coordinate.void
setUpperRightY(float value)
This will set the upper right y coordinate.java.awt.geom.GeneralPath
toGeneralPath()
Returns a general path equivalent to this rectangle.java.lang.String
toString()
This will return a string representation of this rectangle.java.awt.geom.GeneralPath
transform(Matrix matrix)
Returns a path which represents this rectangle having been transformed by the given matrix.
-
-
-
Field Detail
-
POINTS_PER_INCH
private static final float POINTS_PER_INCH
user space units per inch- See Also:
- Constant Field Values
-
POINTS_PER_MM
private static final float POINTS_PER_MM
user space units per millimeter- See Also:
- Constant Field Values
-
LETTER
public static final PDRectangle LETTER
A rectangle the size of U.S. Letter, 8.5" x 11".
-
LEGAL
public static final PDRectangle LEGAL
A rectangle the size of U.S. Legal, 8.5" x 14".
-
A0
public static final PDRectangle A0
A rectangle the size of A0 Paper.
-
A1
public static final PDRectangle A1
A rectangle the size of A1 Paper.
-
A2
public static final PDRectangle A2
A rectangle the size of A2 Paper.
-
A3
public static final PDRectangle A3
A rectangle the size of A3 Paper.
-
A4
public static final PDRectangle A4
A rectangle the size of A4 Paper.
-
A5
public static final PDRectangle A5
A rectangle the size of A5 Paper.
-
A6
public static final PDRectangle A6
A rectangle the size of A6 Paper.
-
rectArray
private final COSArray rectArray
-
-
Constructor Detail
-
PDRectangle
public PDRectangle()
Constructor. Initializes to 0,0,0,0
-
PDRectangle
public PDRectangle(float width, float height)
Constructor.- Parameters:
width
- The width of the rectangle.height
- The height of the rectangle.
-
PDRectangle
public PDRectangle(float x, float y, float width, float height)
Constructor.- Parameters:
x
- the x coordinate of the rectangley
- the y coordinate of the rectanglewidth
- The width of the rectangle.height
- The height of the rectangle.
-
PDRectangle
public PDRectangle(BoundingBox box)
Constructor.- Parameters:
box
- the bounding box to be used for the rectangle
-
PDRectangle
public PDRectangle(COSArray array)
Constructor.- Parameters:
array
- An array of numbers as specified in the PDF Reference for a rectangle type.
-
-
Method Detail
-
contains
public boolean contains(float x, float y)
Method to determine if the x/y point is inside this rectangle.- Parameters:
x
- The x-coordinate to test.y
- The y-coordinate to test.- Returns:
- True if the point is inside this rectangle.
-
createRetranslatedRectangle
public PDRectangle createRetranslatedRectangle()
This will create a translated rectangle based off of this rectangle, such that the new rectangle retains the same dimensions(height/width), but the lower left x,y values are zero.
100, 100, 400, 400 (llx, lly, urx, ury )
will be translated to 0,0,300,300- Returns:
- A new rectangle that has been translated back to the origin.
-
getCOSArray
public COSArray getCOSArray()
This will get the underlying array for this rectangle.- Returns:
- The cos array.
-
getLowerLeftX
public float getLowerLeftX()
This will get the lower left x coordinate.- Returns:
- The lower left x.
-
setLowerLeftX
public void setLowerLeftX(float value)
This will set the lower left x coordinate.- Parameters:
value
- The lower left x.
-
getLowerLeftY
public float getLowerLeftY()
This will get the lower left y coordinate.- Returns:
- The lower left y.
-
setLowerLeftY
public void setLowerLeftY(float value)
This will set the lower left y coordinate.- Parameters:
value
- The lower left y.
-
getUpperRightX
public float getUpperRightX()
This will get the upper right x coordinate.- Returns:
- The upper right x .
-
setUpperRightX
public void setUpperRightX(float value)
This will set the upper right x coordinate.- Parameters:
value
- The upper right x .
-
getUpperRightY
public float getUpperRightY()
This will get the upper right y coordinate.- Returns:
- The upper right y.
-
setUpperRightY
public void setUpperRightY(float value)
This will set the upper right y coordinate.- Parameters:
value
- The upper right y.
-
getWidth
public float getWidth()
This will get the width of this rectangle as calculated by upperRightX - lowerLeftX.- Returns:
- The width of this rectangle.
-
getHeight
public float getHeight()
This will get the height of this rectangle as calculated by upperRightY - lowerLeftY.- Returns:
- The height of this rectangle.
-
transform
public java.awt.geom.GeneralPath transform(Matrix matrix)
Returns a path which represents this rectangle having been transformed by the given matrix. Note that the resulting path need not be rectangular.- Parameters:
matrix
- the matrix to be used for the transformation.- Returns:
- the resulting path.
-
getCOSObject
public COSBase getCOSObject()
Convert this standard java object to a COS object.- Specified by:
getCOSObject
in interfaceCOSObjectable
- Returns:
- The cos object that matches this Java object.
-
toGeneralPath
public java.awt.geom.GeneralPath toGeneralPath()
Returns a general path equivalent to this rectangle. This method avoids the problems caused by Rectangle2D not working well with -ve rectangles.- Returns:
- the general path.
-
toString
public java.lang.String toString()
This will return a string representation of this rectangle.- Overrides:
toString
in classjava.lang.Object
- Returns:
- This object as a string.
-
-