private boolean guessFormat(Rectangle pageSize, boolean rotate) {
        if (rotate) {
            pageSize = pageSize.rotate();
        }
        if (rectEquals(pageSize, PageSize.A3)) {
            pageWidth = 16837;
            pageHeight = 23811;
            landscape = rotate;
            return true;
        }
        if (rectEquals(pageSize, PageSize.A4)) {
            pageWidth = 11907;
            pageHeight = 16840;
            landscape = rotate;
            return true;
        }
        if (rectEquals(pageSize, PageSize.A5)) {
            pageWidth = 8391;
            pageHeight = 11907;
            landscape = rotate;
            return true;
        }
        if (rectEquals(pageSize, PageSize.A6)) {
            pageWidth = 5959;
            pageHeight = 8420;
            landscape = rotate;
            return true;
        }
        if (rectEquals(pageSize, PageSize.B4)) {
            pageWidth = 14570;
            pageHeight = 20636;
            landscape = rotate;
            return true;
        }
        if (rectEquals(pageSize, PageSize.B5)) {
            pageWidth = 10319;
            pageHeight = 14572;
            landscape = rotate;
            return true;
        }
        if (rectEquals(pageSize, PageSize.HALFLETTER)) {
            pageWidth = 7927;
            pageHeight = 12247;
            landscape = rotate;
            return true;
        }
        if (rectEquals(pageSize, PageSize.LETTER)) {
            pageWidth = 12242;
            pageHeight = 15842;
            landscape = rotate;
            return true;
        }
        if (rectEquals(pageSize, PageSize.LEGAL)) {
            pageWidth = 12252;
            pageHeight = 20163;
            landscape = rotate;
            return true;
        }
        if (!rotate && guessFormat(pageSize, true)) {
            int x = pageWidth;
            pageWidth = pageHeight;
            pageHeight = x;
            return true;
        }
        return false;
    }
private boolean guessFormat ( Rectangle pageSize , boolean rotate ) { if ( rotate ) { pageSize = pageSize . rotate ( ) ; } if ( rectEquals ( pageSize , PageSize . A3 ) ) { pageWidth = 16837 ; pageHeight = 23811 ; landscape = rotate ; return true ; } if ( rectEquals ( pageSize , PageSize . A4 ) ) { pageWidth = 11907 ; pageHeight = 16840 ; landscape = rotate ; return true ; } if ( rectEquals ( pageSize , PageSize . A5 ) ) { pageWidth = 8391 ; pageHeight = 11907 ; landscape = rotate ; return true ; } if ( rectEquals ( pageSize , PageSize . A6 ) ) { pageWidth = 5959 ; pageHeight = 8420 ; landscape = rotate ; return true ; } if ( rectEquals ( pageSize , PageSize . B4 ) ) { pageWidth = 14570 ; pageHeight = 20636 ; landscape = rotate ; return true ; } if ( rectEquals ( pageSize , PageSize . B5 ) ) { pageWidth = 10319 ; pageHeight = 14572 ; landscape = rotate ; return true ; } if ( rectEquals ( pageSize , PageSize . HALFLETTER ) ) { pageWidth = 7927 ; pageHeight = 12247 ; landscape = rotate ; return true ; } if ( rectEquals ( pageSize , PageSize . LETTER ) ) { pageWidth = 12242 ; pageHeight = 15842 ; landscape = rotate ; return true ; } if ( rectEquals ( pageSize , PageSize . LEGAL ) ) { pageWidth = 12252 ; pageHeight = 20163 ; landscape = rotate ; return true ; } if ( ! rotate && guessFormat ( pageSize , true ) ) { int x = pageWidth ; pageWidth = pageHeight ; pageHeight = x ; return true ; } return false ; }
This method tries to fit the <code>Rectangle pageSize</code> to one of the predefined PageSize rectangles.
If a match is found the pageWidth and pageHeight will be set according to values determined from files
generated by MS Word2000 and OpenOffice 641. If no match is found the method will try to match the rotated
Rectangle by calling itself with the parameter rotate set to true.

@param pageSize the page size for which to guess the correct format
@param rotate Whether we should try to rotate the size befor guessing the format
@return <code>True</code> if the format was guessed, <code>false/<code> otherwise