List of usage examples for java.awt.print Paper Paper
public Paper()
From source file:com.servoy.j2db.util.Utils.java
/** * Create a PageFormat object from the dimensions and margins. * * @param width the actual paper width - ignoring orientation. It is the width of the paper as seen by the printer. * @param height the actual paper height - ignoring orientation. It is the height of the paper as seen by the printer. * @param lm left margin of the page, not paper. So this is the left margin affected by orientation, as used in application. * @param rm right margin of the page, not paper. So this is the right margin affected by orientation, as used in application. * @param tm top margin of the page, not paper. So this is the top margin affected by orientation, as used in application. * @param bm bottom margin of the page, not paper. So this is the bottom margin affected by orientation, as used in application. * @param orientation the orientation of the page. Establishes a relation between page and paper coordinates. * @param units INCHES or MM.//from w w w . jav a 2s . c om * @return the required PageFormat object. */ public static PageFormat createPageFormat(double width, double height, double lm, double rm, double tm, double bm, int orientation, int units) { double pixWidth = convertPageFormatUnit(units, Size2DSyntax.INCH, width) * PPI; double pixHeight = convertPageFormatUnit(units, Size2DSyntax.INCH, height) * PPI; double pixLm = convertPageFormatUnit(units, Size2DSyntax.INCH, lm) * PPI; double pixRm = convertPageFormatUnit(units, Size2DSyntax.INCH, rm) * PPI; double pixTm = convertPageFormatUnit(units, Size2DSyntax.INCH, tm) * PPI; double pixBm = convertPageFormatUnit(units, Size2DSyntax.INCH, bm) * PPI; // The margins of the Paper object are relative to the physical paper, so independent // of the text orientation; The PageFormat object takes the orientation into account relative to the text. // We have to convert back to the paper-relative margins here... double paperLm; double paperRm; double paperTm; double paperBm; if (orientation == PageFormat.LANDSCAPE) { paperLm = pixTm; paperRm = pixBm; paperTm = pixRm; paperBm = pixLm; } else if (orientation == PageFormat.PORTRAIT) { paperLm = pixLm; paperRm = pixRm; paperTm = pixTm; paperBm = pixBm; } else // orientation == PageFormat.REVERSE_LANDSCAPE { paperLm = pixBm; paperRm = pixTm; paperTm = pixLm; paperBm = pixRm; } PageFormat pf = new PageFormat(); pf.setOrientation(orientation); Paper paper = new Paper(); paper.setSize(pixWidth, pixHeight); paper.setImageableArea(paperLm, paperTm, pixWidth - (paperLm + paperRm), pixHeight - (paperTm + paperBm)); pf.setPaper(paper); return pf; }