code: public static Rectangle getRectangle(String name)  {
      	name = name.trim().toUpperCase();
      	int pos = name.indexOf(' ');
          if (pos == -1) {
              try {            
                  Field field = PageSize.class.getDeclaredField(name.toUpperCase());
                  return (Rectangle) field.get(null);
              } catch (Exception e) {
                  throw new RuntimeException("Can't find page size " + name);          
              }
          }
          else {
          	try {
          		String width = name.substring(0, pos);
          		String height = name.substring(pos + 1);
          		return new Rectangle(Float.parseFloat(width), Float.parseFloat(height));
          	} catch(Exception e) {
          		throw new RuntimeException(name + " is not a valid page size format; " + e.getMessage());
          	}
          }
      }
docs: This method returns a Rectangle based on a String.
  Possible values are the the names of a constant in this class
  (for instance "A4", "LETTER",...) or a value like "595 842"