List of usage examples for java.awt.print PageFormat PORTRAIT
int PORTRAIT
To view the source code for java.awt.print PageFormat PORTRAIT.
Click Source Link
From source file:Main.java
public static void main(String[] argv) throws Exception { PrinterJob pjob = PrinterJob.getPrinterJob(); PageFormat pf = pjob.defaultPage(); pf.setOrientation(PageFormat.PORTRAIT); pf.setOrientation(PageFormat.LANDSCAPE); // pjob.setPrintable(printable, pf); pjob.print();/* w w w. j a va 2s . co m*/ }
From source file:PrintBook.java
public static void main(String[] args) { PrinterJob pjob = PrinterJob.getPrinterJob(); Book book = new Book(); PageFormat landscape = pjob.defaultPage(); landscape.setOrientation(PageFormat.LANDSCAPE); book.append(new Printable1(), landscape); PageFormat portrait = pjob.defaultPage(); portrait.setOrientation(PageFormat.PORTRAIT); book.append(new Printable2(), portrait, 5); pjob.setPageable(book);//from ww w . j ava2 s . c o m try { pjob.print(); } catch (PrinterException e) { } }
From source file:com.floreantpos.jasperreport.engine.print.JRPrinterAWT.java
/** * */// w w w . j a v a2 s . co m private boolean printPages(int firstPageIndex, int lastPageIndex, boolean withPrintDialog) throws JRException { boolean isOK = true; if (firstPageIndex < 0 || firstPageIndex > lastPageIndex || lastPageIndex >= jasperPrint.getPages().size()) { throw new JRException("Invalid page index range : " + firstPageIndex + " - " + lastPageIndex + " of " + jasperPrint.getPages().size()); } printerName = jasperPrint.getProperty("printerName"); pageOffset = firstPageIndex; PrinterJob printJob = PrinterJob.getPrinterJob(); // fix for bug ID 6255588 from Sun bug database initPrinterJobFields(printJob); PageFormat pageFormat = printJob.defaultPage(); Paper paper = pageFormat.getPaper(); printJob.setJobName(jasperPrint.getName()); switch (jasperPrint.getOrientationValue()) { case LANDSCAPE: { pageFormat.setOrientation(PageFormat.LANDSCAPE); paper.setSize(jasperPrint.getPageHeight(), jasperPrint.getPageWidth()); paper.setImageableArea(0, 0, jasperPrint.getPageHeight(), jasperPrint.getPageWidth()); break; } case PORTRAIT: default: { pageFormat.setOrientation(PageFormat.PORTRAIT); paper.setSize(jasperPrint.getPageWidth(), jasperPrint.getPageHeight()); paper.setImageableArea(0, 0, jasperPrint.getPageWidth(), jasperPrint.getPageHeight()); } } pageFormat.setPaper(paper); Book book = new Book(); book.append(this, pageFormat, lastPageIndex - firstPageIndex + 1); printJob.setPageable(book); try { if (withPrintDialog) { if (printJob.printDialog()) { printJob.print(); } else { isOK = false; } } else { printJob.print(); } } catch (Exception ex) { throw new JRException("Error printing report.", ex); } return isOK; }
From source file:com.openbravo.pos.util.JRPrinterAWT411.java
/** * *///ww w . j a va2 s . c om private boolean printPages(int firstPageIndex, int lastPageIndex, PrintService service) throws JRException { boolean isOK = true; if (firstPageIndex < 0 || firstPageIndex > lastPageIndex || lastPageIndex >= jasperPrint.getPages().size()) { throw new JRException("Invalid page index range : " + firstPageIndex + " - " + lastPageIndex + " of " + jasperPrint.getPages().size()); } pageOffset = firstPageIndex; PrinterJob printJob = PrinterJob.getPrinterJob(); // fix for bug ID 6255588 from Sun bug database initPrinterJobFields(printJob); PageFormat pageFormat = printJob.defaultPage(); Paper paper = pageFormat.getPaper(); printJob.setJobName("JasperReports - " + jasperPrint.getName()); switch (jasperPrint.getOrientationValue()) { case LANDSCAPE: { pageFormat.setOrientation(PageFormat.LANDSCAPE); paper.setSize(jasperPrint.getPageHeight(), jasperPrint.getPageWidth()); paper.setImageableArea(0, 0, jasperPrint.getPageHeight(), jasperPrint.getPageWidth()); break; } case PORTRAIT: default: { pageFormat.setOrientation(PageFormat.PORTRAIT); paper.setSize(jasperPrint.getPageWidth(), jasperPrint.getPageHeight()); paper.setImageableArea(0, 0, jasperPrint.getPageWidth(), jasperPrint.getPageHeight()); } } pageFormat.setPaper(paper); Book book = new Book(); book.append(this, pageFormat, lastPageIndex - firstPageIndex + 1); printJob.setPageable(book); try { if (service == null) { if (printJob.printDialog()) { printJob.print(); } else { isOK = false; } } else { printJob.setPrintService(service); printJob.print(); } } catch (Exception ex) { throw new JRException("Error printing report.", ex); } return isOK; }
From source file:com.openbravo.pos.util.JRPrinterAWT.java
/** * *///from w w w . j a va 2s. c o m public boolean printPages(int firstPageIndex, int lastPageIndex, PrintService service) throws JRException { boolean isOK = true; if (firstPageIndex < 0 || firstPageIndex > lastPageIndex || lastPageIndex >= jasperPrint.getPages().size()) { throw new JRException("Invalid page index range : " + firstPageIndex + " - " + lastPageIndex + " of " + jasperPrint.getPages().size()); } pageOffset = firstPageIndex; PrinterJob printJob = PrinterJob.getPrinterJob(); // fix for bug ID 6255588 from Sun bug database initPrinterJobFields(printJob); PageFormat pageFormat = printJob.defaultPage(); Paper paper = pageFormat.getPaper(); printJob.setJobName("JasperReports - " + jasperPrint.getName()); switch (jasperPrint.getOrientationValue()) { case LANDSCAPE: { pageFormat.setOrientation(PageFormat.LANDSCAPE); paper.setSize(jasperPrint.getPageHeight(), jasperPrint.getPageWidth()); paper.setImageableArea(0, 0, jasperPrint.getPageHeight(), jasperPrint.getPageWidth()); break; } case PORTRAIT: default: { pageFormat.setOrientation(PageFormat.PORTRAIT); paper.setSize(jasperPrint.getPageWidth(), jasperPrint.getPageHeight()); paper.setImageableArea(0, 0, jasperPrint.getPageWidth(), jasperPrint.getPageHeight()); } } pageFormat.setPaper(paper); Book book = new Book(); book.append(this, pageFormat, lastPageIndex - firstPageIndex + 1); printJob.setPageable(book); try { if (service == null) { if (printJob.printDialog()) { printJob.print(); } else { isOK = false; } } else { printJob.setPrintService(service); printJob.print(); } } catch (Exception ex) { throw new JRException("Error printing report.", ex); } return isOK; }
From source file:net.sf.jasperreports.engine.print.JRPrinterAWT.java
/** * */// w w w. j a v a2 s. c om public boolean printPages(int firstPageIndex, int lastPageIndex, boolean withPrintDialog) throws JRException { boolean isOK = true; if (firstPageIndex < 0 || firstPageIndex > lastPageIndex || lastPageIndex >= jasperPrint.getPages().size()) { throw new JRException("Invalid page index range : " + firstPageIndex + " - " + lastPageIndex + " of " + jasperPrint.getPages().size()); } pageOffset = firstPageIndex; PrinterJob printJob = PrinterJob.getPrinterJob(); // fix for bug ID 6255588 from Sun bug database initPrinterJobFields(printJob); if (jasperPrint.getProperty("printService") != null) { String printServiceName = jasperPrint.getProperty("printService"); try { PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null); for (PrintService se : services) { if (se.getName().contains(printServiceName)) { printJob.setPrintService(se); break; } } } catch (PrinterException ex) { Logger.getLogger(JRPrinterAWT.class.getName()).log(Level.SEVERE, null, ex); } } PageFormat pageFormat = printJob.defaultPage(); Paper paper = pageFormat.getPaper(); printJob.setJobName("JasperReports - " + jasperPrint.getName()); switch (jasperPrint.getOrientationValue()) { case LANDSCAPE: { pageFormat.setOrientation(PageFormat.LANDSCAPE); paper.setSize(jasperPrint.getPageHeight(), jasperPrint.getPageWidth()); paper.setImageableArea(0, 0, jasperPrint.getPageHeight(), jasperPrint.getPageWidth()); break; } case PORTRAIT: default: { pageFormat.setOrientation(PageFormat.PORTRAIT); paper.setSize(jasperPrint.getPageWidth(), jasperPrint.getPageHeight()); paper.setImageableArea(0, 0, jasperPrint.getPageWidth(), jasperPrint.getPageHeight()); } } pageFormat.setPaper(paper); Book book = new Book(); book.append(this, pageFormat, lastPageIndex - firstPageIndex + 1); printJob.setPageable(book); try { if (withPrintDialog) { if (printJob.printDialog()) { printJob.print(); } else { isOK = false; } } else { printJob.print(); } } catch (Exception ex) { throw new JRException("Error printing report.", ex); } return isOK; }
From source file:freemind.controller.Controller.java
private boolean acquirePrinterJobAndPageFormat() { if (printerJob == null) { try {// w w w . j a v a2 s . co m printerJob = PrinterJob.getPrinterJob(); } catch (SecurityException ex) { isPrintingAllowed = false; return false; } } if (pageFormat == null) { pageFormat = printerJob.defaultPage(); if (Tools.safeEquals(getProperty("page_orientation"), "landscape")) { pageFormat.setOrientation(PageFormat.LANDSCAPE); } else if (Tools.safeEquals(getProperty("page_orientation"), "portrait")) { pageFormat.setOrientation(PageFormat.PORTRAIT); } else if (Tools.safeEquals(getProperty("page_orientation"), "reverse_landscape")) { pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE); } } return true; }
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 www . j a v 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.core.modules.parser.bundle.layout.PageDefinitionReadHandler.java
/** * Creates the pageFormat by using the given Attributes. If an PageFormat name is given, the named PageFormat is used * and the parameters width and height are ignored. If no name is defined, height and width attributes are used to * create the pageformat. The attributes define the dimension of the PageFormat in points, where the printing * resolution is defined at 72 pixels per inch. * * @param defaultPageFormat/*w ww . jav a2s . c o m*/ * the page format. * @param atts * the element attributes. * @return the page format. * @throws SAXException * if there is an error parsing the report. */ private PageFormat configurePageSize(final PageFormat defaultPageFormat, final Attributes atts) throws SAXException { final String pageformatName = atts.getValue(getUri(), "pageformat"); final int orientationVal; final String orientation = atts.getValue(getUri(), "orientation"); if (orientation == null) { orientationVal = PageFormat.PORTRAIT; } else if ("landscape".equals(orientation)) { orientationVal = PageFormat.LANDSCAPE; } else if ("reverse-landscape".equals(orientation)) { orientationVal = PageFormat.REVERSE_LANDSCAPE; } else { orientationVal = PageFormat.PORTRAIT; } if (pageformatName != null) { final Paper p = PageFormatFactory.getInstance().createPaper(pageformatName); if (p == null) { PageDefinitionReadHandler.logger.warn("Paper size '" + pageformatName + "' is not regognized."); return defaultPageFormat; } return PageFormatFactory.getInstance().createPageFormat(p, orientationVal); } if (atts.getValue(getUri(), "width") != null && atts.getValue(getUri(), "height") != null) { final int[] pageformatData = new int[2]; pageformatData[0] = ParserUtil.parseInt(atts.getValue(getUri(), "width"), "Specified attribute 'width' is not valid", getLocator()); pageformatData[1] = ParserUtil.parseInt(atts.getValue(getUri(), "height"), "Specified attribute 'height' is not valid", getLocator()); final Paper p = PageFormatFactory.getInstance().createPaper(pageformatData); if (p == null) { PageDefinitionReadHandler.logger.warn("Unable to create the requested Paper size with width " + pageformatData[0] + " and height " + pageformatData[1]); return defaultPageFormat; } return PageFormatFactory.getInstance().createPageFormat(p, orientationVal); } PageDefinitionReadHandler.logger.info("Insufficient Data to create a pageformat: Returned default."); return defaultPageFormat; }
From source file:org.pentaho.reporting.engine.classic.core.modules.parser.bundle.layout.PageDefinitionReadHandler.java
/** * Handles the page format./*from ww w . j a v a 2 s. c o m*/ * * @param atts * the attributes. * @throws SAXException * if a parser error occurs or the validation failed. * @noinspection SuspiciousNameCombination */ private PageFormat configurePageSizeAndMargins(final Attributes atts, PageFormat format) throws SAXException { // (1) Grab the existing default ... float defTopMargin = (float) format.getImageableY(); float defBottomMargin = (float) (format.getHeight() - format.getImageableHeight() - format.getImageableY()); float defLeftMargin = (float) format.getImageableX(); float defRightMargin = (float) (format.getWidth() - format.getImageableWidth() - format.getImageableX()); // (2) Now configure the new paper-size format = configurePageSize(format, atts); // (3) Reconfigure margins as requested defTopMargin = ParserUtil.parseFloat(atts.getValue(getUri(), "margin-top"), defTopMargin); defBottomMargin = ParserUtil.parseFloat(atts.getValue(getUri(), "margin-bottom"), defBottomMargin); defLeftMargin = ParserUtil.parseFloat(atts.getValue(getUri(), "margin-left"), defLeftMargin); defRightMargin = ParserUtil.parseFloat(atts.getValue(getUri(), "margin-right"), defRightMargin); final Paper p = format.getPaper(); switch (format.getOrientation()) { case PageFormat.PORTRAIT: PageFormatFactory.getInstance().setBorders(p, defTopMargin, defLeftMargin, defBottomMargin, defRightMargin); break; case PageFormat.REVERSE_LANDSCAPE: PageFormatFactory.getInstance().setBorders(p, defLeftMargin, defBottomMargin, defRightMargin, defTopMargin); break; case PageFormat.LANDSCAPE: PageFormatFactory.getInstance().setBorders(p, defRightMargin, defTopMargin, defLeftMargin, defBottomMargin); break; default: // will not happen.. throw new IllegalArgumentException("Unexpected paper orientation."); } format.setPaper(p); return format; }