Class Size

java.lang.Object
com.pdftools.geometry.units.Size

public class Size extends Object

Class that represents a size that is based on a width and height of type Length.

Constructs from standard paper sizes, generates a string representation, and provides conversions to portrait and landscape mode.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Size(double width, double height, Length.Units unit)
    Construct Size object from width, height and a common unit.
    Size(Length width, Length height)
    Construct Size object from width and height.
    Size(Size.PaperSizes paperSize)
    Construct a Size object from standard paper sizes defined in enum Size.PaperSizes.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    double
    Calculate ratio between height and width.
    Gets the height (vertical size) as Length object.
    Gets the width (horizontal size) as Length object.
    int
     
    static Size
    parse(String value)
    Create a Size object from a string representation.
    Switches width and height if the absolute value of height is greater than the the absolute value of width.
    Switches width and height if the absolute value of the width is greater than the absolute value of the height.
    Creates a string representation as width-height-pair with associated suitable metric units, "m", "cm" or "mm".
    Creates a string representation as width-height-pair with the specified unit.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

  • Method Details

    • parse

      public static Size parse(String value)

      Create a Size object from a string representation.

      Allowed are value-unit pairs of the form "<width_value><width_unit> <height_value><height_unit>" or the name of a standard paper size.

      Examples: "12.3cm 23.9mm" or "A4"

      Parameters:
      value - the string value
      Returns:
    • toString

      public String toString()
      Creates a string representation as width-height-pair with associated suitable metric units, "m", "cm" or "mm".
      Overrides:
      toString in class Object
    • toString

      public String toString(Length.Units unit)
      Creates a string representation as width-height-pair with the specified unit.
    • toPortrait

      public Size toPortrait()
      Switches width and height if the absolute value of the width is greater than the absolute value of the height.
    • toLandscape

      public Size toLandscape()
      Switches width and height if the absolute value of height is greater than the the absolute value of width.
    • getAspectRatio

      public double getAspectRatio()
      Calculate ratio between height and width.
    • getWidth

      public Length getWidth()
      Gets the width (horizontal size) as Length object.
    • getHeight

      public Length getHeight()
      Gets the height (vertical size) as Length object.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object