public static void setPageMargins(PrintService service, PrintRequestAttributeSet set, double[] margins, LengthUnits units) {
		PageOrientation orientation = getPageOrientation(service, set);

		if (orientation == PageOrientation.LANDSCAPE) {
			setPaperMargins(service, set, new double[] { margins[3], margins[0], margins[1], margins[2] }, units);
		} else if (orientation == PageOrientation.REVERSE_PORTRAIT) {
			setPaperMargins(service, set, new double[] { margins[2], margins[3], margins[0], margins[1] }, units);
		} else if (orientation == PageOrientation.REVERSE_LANDSCAPE) {
			setPaperMargins(service, set, new double[] { margins[1], margins[2], margins[3], margins[0] }, units);
		} else {
			setPaperMargins(service, set, margins, units);
		}
	}