List of usage examples for javax.print.attribute Size2DSyntax INCH
int INCH
To view the source code for javax.print.attribute Size2DSyntax INCH.
Click Source Link
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.// w w w. jav a 2 s .c o m * @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; }
From source file:org.pentaho.reporting.engine.classic.extensions.modules.java14print.Java14PrintUtil.java
/** * This method replaces the media definition from the given attribute set with the one found in the report itself. * <p/>//from w w w . j a v a 2 s . c o m * If no JobName is set, a default jobname will be assigned. * * @param attributes * @param report * @return */ public static PrintRequestAttributeSet copyConfiguration(PrintRequestAttributeSet attributes, final MasterReport report) { if (attributes == null) { attributes = new HashPrintRequestAttributeSet(); } // for now, be lazy, assume that the first page is the reference final PageDefinition pdef = report.getPageDefinition(); final PageFormat format = pdef.getPageFormat(0); final Paper paper = format.getPaper(); final Media media = MediaSize.findMedia((float) (paper.getWidth() / POINTS_PER_INCH), (float) (paper.getHeight() / POINTS_PER_INCH), Size2DSyntax.INCH); attributes.add(media); final MediaPrintableArea printableArea = new MediaPrintableArea( (float) (paper.getImageableX() / POINTS_PER_INCH), (float) (paper.getImageableY() / POINTS_PER_INCH), (float) (paper.getImageableWidth() / POINTS_PER_INCH), (float) (paper.getImageableHeight() / POINTS_PER_INCH), Size2DSyntax.INCH); attributes.add(printableArea); attributes.add(mapOrientation(format.getOrientation())); return attributes; }
From source file:org.pentaho.reporting.engine.classic.extensions.modules.java14print.Java14PrintUtil.java
private static Paper createPaper(final MediaSize mediaSize, final MediaPrintableArea printableArea) { final Paper paper = new Paper(); if (mediaSize != null) { paper.setSize(mediaSize.getX(Size2DSyntax.INCH) * POINTS_PER_INCH, mediaSize.getY(Size2DSyntax.INCH) * POINTS_PER_INCH); }//from www. j a va 2 s. co m if (printableArea != null) { paper.setImageableArea(printableArea.getX(Size2DSyntax.INCH) * POINTS_PER_INCH, printableArea.getY(Size2DSyntax.INCH) * POINTS_PER_INCH, printableArea.getWidth(Size2DSyntax.INCH) * POINTS_PER_INCH, printableArea.getHeight(Size2DSyntax.INCH) * POINTS_PER_INCH); } return paper; }