Java Code Examples for java.awt.print.PrinterJob#setPageable()
The following examples show how to use
java.awt.print.PrinterJob#setPageable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WrongPaperForBookPrintingTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 7 votes |
private static void doTest() { PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(Chromaticity.MONOCHROME); MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5); float[] size = isoA5Size.getSize(Size2DSyntax.INCH); Paper paper = new Paper(); paper.setSize(size[0] * 72.0, size[1] * 72.0); paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0); PageFormat pf = new PageFormat(); pf.setPaper(paper); Book pageable = new Book(); pageable.append(new WrongPaperForBookPrintingTest(), pf); PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(pageable); if (job.printDialog()) { try { job.print(aset); } catch (PrinterException pe) { throw new RuntimeException(pe); } } }
Example 2
Source File: WrongPaperForBookPrintingTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
private static void doTest() { PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(Chromaticity.MONOCHROME); MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5); float[] size = isoA5Size.getSize(Size2DSyntax.INCH); Paper paper = new Paper(); paper.setSize(size[0] * 72.0, size[1] * 72.0); paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0); PageFormat pf = new PageFormat(); pf.setPaper(paper); Book pageable = new Book(); pageable.append(new WrongPaperForBookPrintingTest(), pf); PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(pageable); if (job.printDialog()) { try { job.print(aset); } catch (PrinterException pe) { throw new RuntimeException(pe); } } }
Example 3
Source File: SnapshotTool.java From osp with GNU General Public License v3.0 | 6 votes |
public void print() { PrinterJob printerJob = PrinterJob.getPrinterJob(); PageFormat format = new PageFormat(); java.awt.print.Book book = new java.awt.print.Book(); book.append(this, format); printerJob.setPageable(book); if(printerJob.printDialog()) { try { printerJob.print(); } catch(PrinterException pe) { // JOptionPane.showMessageDialog(c, // TrackerRes.getString("TActions.Dialog.PrintError.Message"), //$NON-NLS-1$ // TrackerRes.getString("TActions.Dialog.PrintError.Title"), //$NON-NLS-1$ // JOptionPane.ERROR_MESSAGE); } } }
Example 4
Source File: PrintUtil.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
public static void printDirectly( final MasterReport report, final ReportProgressListener progressListener ) throws PrinterException, ReportProcessingException { final ModifiableConfiguration reportConfiguration = report.getReportConfiguration(); final String jobName = reportConfiguration.getConfigProperty( PRINTER_JOB_NAME_KEY, report.getTitle() ); final PrinterJob printerJob = PrinterJob.getPrinterJob(); if ( jobName != null ) { printerJob.setJobName( jobName ); } final PrintReportProcessor reportPane = new PrintReportProcessor( report ); if ( progressListener != null ) { reportPane.addReportProgressListener( progressListener ); } printerJob.setPageable( reportPane ); try { printerJob.setCopies( getNumberOfCopies( reportConfiguration ) ); printerJob.print(); } finally { reportPane.close(); if ( progressListener != null ) { reportPane.removeReportProgressListener( progressListener ); } } }
Example 5
Source File: PrintPageDirect.java From haxademic with MIT License | 6 votes |
public void sendToDefaultPrinter() { // configure the printing job & simple single-page document PrinterJob printJob = PrinterJob.getPrinterJob(); Book book = new Book(); book.append(new ImagePage(), printJob.defaultPage()); PageFormat documentPageFormat = new PageFormat(); /* // new settings to play with Paper pape = new Paper(); pape.setSize(10000, 6000); pape.setImageableArea(0, 0, 10000, 6000); documentPageFormat.setPaper(pape); */ documentPageFormat.setOrientation(PageFormat.LANDSCAPE); printJob.setPageable(book); // use the print dialog UI or just print it! if(useDialog) { if (printJob.printDialog()) printPage(printJob); } else { printPage(printJob); } }
Example 6
Source File: PrintAttributeUpdateTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String args[]) throws Exception { String[] instructions = { "Select Pages Range From instead of All in print dialog. ", "Then select Print" }; SwingUtilities.invokeAndWait(() -> { JOptionPane.showMessageDialog((Component) null, instructions, "Instructions", JOptionPane.INFORMATION_MESSAGE); }); HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet(); PrinterJob j = PrinterJob.getPrinterJob(); j.setPageable(new PrintAttributeUpdateTest()); as.add(DialogTypeSelection.NATIVE); j.printDialog(as); if (as.containsKey(PageRanges.class) == false) { throw new RuntimeException("Print Dialog did not update " + " attribute set with page range"); } Attribute attrs[] = as.toArray(); for (int i = 0; i < attrs.length; i++) { System.out.println("attr " + attrs[i]); } j.print(as); }
Example 7
Source File: WrongPaperForBookPrintingTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static void doTest() { PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(Chromaticity.MONOCHROME); MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5); float[] size = isoA5Size.getSize(Size2DSyntax.INCH); Paper paper = new Paper(); paper.setSize(size[0] * 72.0, size[1] * 72.0); paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0); PageFormat pf = new PageFormat(); pf.setPaper(paper); Book pageable = new Book(); pageable.append(new WrongPaperForBookPrintingTest(), pf); PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(pageable); if (job.printDialog()) { try { job.print(aset); } catch (PrinterException pe) { throw new RuntimeException(pe); } } }
Example 8
Source File: PrintAttributeUpdateTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String args[]) throws Exception { String[] instructions = { "Select Pages Range From instead of All in print dialog. ", "Then select Print" }; SwingUtilities.invokeAndWait(() -> { JOptionPane.showMessageDialog((Component) null, instructions, "Instructions", JOptionPane.INFORMATION_MESSAGE); }); HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet(); PrinterJob j = PrinterJob.getPrinterJob(); j.setPageable(new PrintAttributeUpdateTest()); as.add(DialogTypeSelection.NATIVE); j.printDialog(as); if (as.containsKey(PageRanges.class) == false) { throw new RuntimeException("Print Dialog did not update " + " attribute set with page range"); } Attribute attrs[] = as.toArray(); for (int i = 0; i < attrs.length; i++) { System.out.println("attr " + attrs[i]); } j.print(as); }
Example 9
Source File: PrintAttributeUpdateTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public static void main(String args[]) throws Exception { String[] instructions = { "Select Pages Range From instead of All in print dialog. ", "Then select Print" }; SwingUtilities.invokeAndWait(() -> { JOptionPane.showMessageDialog((Component) null, instructions, "Instructions", JOptionPane.INFORMATION_MESSAGE); }); HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet(); PrinterJob j = PrinterJob.getPrinterJob(); j.setPageable(new PrintAttributeUpdateTest()); as.add(DialogTypeSelection.NATIVE); j.printDialog(as); if (as.containsKey(PageRanges.class) == false) { throw new RuntimeException("Print Dialog did not update " + " attribute set with page range"); } Attribute attrs[] = as.toArray(); for (int i = 0; i < attrs.length; i++) { System.out.println("attr " + attrs[i]); } j.print(as); }
Example 10
Source File: PrintAttributeUpdateTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String args[]) throws Exception { String[] instructions = { "Select Pages Range From instead of All in print dialog. ", "Then select Print" }; SwingUtilities.invokeAndWait(() -> { JOptionPane.showMessageDialog((Component) null, instructions, "Instructions", JOptionPane.INFORMATION_MESSAGE); }); HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet(); PrinterJob j = PrinterJob.getPrinterJob(); j.setPageable(new PrintAttributeUpdateTest()); as.add(DialogTypeSelection.NATIVE); j.printDialog(as); if (as.containsKey(PageRanges.class) == false) { throw new RuntimeException("Print Dialog did not update " + " attribute set with page range"); } Attribute attrs[] = as.toArray(); for (int i = 0; i < attrs.length; i++) { System.out.println("attr " + attrs[i]); } j.print(as); }
Example 11
Source File: PrintAttributeUpdateTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String args[]) throws Exception { String[] instructions = { "Select Pages Range From instead of All in print dialog. ", "Then select Print" }; SwingUtilities.invokeAndWait(() -> { JOptionPane.showMessageDialog((Component) null, instructions, "Instructions", JOptionPane.INFORMATION_MESSAGE); }); HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet(); PrinterJob j = PrinterJob.getPrinterJob(); j.setPageable(new PrintAttributeUpdateTest()); as.add(DialogTypeSelection.NATIVE); j.printDialog(as); if (as.containsKey(PageRanges.class) == false) { throw new RuntimeException("Print Dialog did not update " + " attribute set with page range"); } Attribute attrs[] = as.toArray(); for (int i = 0; i < attrs.length; i++) { System.out.println("attr " + attrs[i]); } j.print(as); }
Example 12
Source File: PrintAttributeUpdateTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String args[]) throws Exception { String[] instructions = { "Select Pages Range From instead of All in print dialog. ", "Then select Print" }; SwingUtilities.invokeAndWait(() -> { JOptionPane.showMessageDialog((Component) null, instructions, "Instructions", JOptionPane.INFORMATION_MESSAGE); }); HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet(); PrinterJob j = PrinterJob.getPrinterJob(); j.setPageable(new PrintAttributeUpdateTest()); as.add(DialogTypeSelection.NATIVE); j.printDialog(as); if (as.containsKey(PageRanges.class) == false) { throw new RuntimeException("Print Dialog did not update " + " attribute set with page range"); } Attribute attrs[] = as.toArray(); for (int i = 0; i < attrs.length; i++) { System.out.println("attr " + attrs[i]); } j.print(as); }
Example 13
Source File: PrintDlgPageable.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void printTest() { PrinterJob pj = PrinterJob.getPrinterJob(); PageableHandler handler = new PageableHandler(); pj.setPageable(handler); PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet(); pSet.add(DialogTypeSelection.COMMON); pj.printDialog(pSet); }
Example 14
Source File: PrintPageDirect.java From haxademic with MIT License | 5 votes |
/** * Constructor: Example3 * <p> * */ public void doPrintDemo() { //--- Create a new PrinterJob object PrinterJob printJob = PrinterJob.getPrinterJob(); //--- Create a new book to add pages to Book book = new Book(); //--- Add the cover page using the default page format for this print job book.append(new ImagePage(), printJob.defaultPage()); // book.append(new IntroPage(), printJob.defaultPage()); //--- Add the document page using a landscape page format PageFormat documentPageFormat = new PageFormat(); documentPageFormat.setOrientation(PageFormat.PORTRAIT); // book.append(new Document(), documentPageFormat); //--- Add a third page using the same painter // book.append(new Document(), documentPageFormat); //--- Tell the printJob to use the book as the pageable object printJob.setPageable(book); //--- Show the print dialog box. If the user click the //--- print button we then proceed to print else we cancel //--- the process. // remove the print dialog and just print it! // if (printJob.printDialog()) { try { printJob.print(); } catch (Exception PrintException) { PrintException.printStackTrace(); } // } }
Example 15
Source File: WrongPaperForBookPrintingTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void doTest() { PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(Chromaticity.MONOCHROME); MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5); float[] size = isoA5Size.getSize(Size2DSyntax.INCH); Paper paper = new Paper(); paper.setSize(size[0] * 72.0, size[1] * 72.0); paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0); PageFormat pf = new PageFormat(); pf.setPaper(paper); Book pageable = new Book(); pageable.append(new WrongPaperForBookPrintingTest(), pf); PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(pageable); if (job.printDialog()) { try { job.print(aset); } catch (PrinterException pe) { throw new RuntimeException(pe); } } }
Example 16
Source File: PrintUtil.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public static boolean print( final MasterReport report, final ReportProgressListener progressListener ) throws PrinterException, ReportProcessingException { final ModifiableConfiguration reportConfiguration = report.getReportConfiguration(); final String jobName = reportConfiguration.getConfigProperty( PRINTER_JOB_NAME_KEY, report.getTitle() ); final PrinterJob printerJob = PrinterJob.getPrinterJob(); if ( jobName != null ) { printerJob.setJobName( jobName ); } final PrintReportProcessor reportPane = new PrintReportProcessor( report ); if ( progressListener != null ) { reportPane.addReportProgressListener( progressListener ); } try { reportPane.fireProcessingStarted(); printerJob.setPageable( reportPane ); printerJob.setCopies( getNumberOfCopies( reportConfiguration ) ); if ( printerJob.printDialog() ) { printerJob.print(); return true; } return false; } finally { reportPane.fireProcessingFinished(); reportPane.close(); if ( progressListener != null ) { reportPane.removeReportProgressListener( progressListener ); } } }
Example 17
Source File: JRPrinterAWT.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
/** * */ 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( EXCEPTION_MESSAGE_KEY_INVALID_PAGE_RANGE, new Object[]{firstPageIndex, lastPageIndex, 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 (withPrintDialog) { if (printJob.printDialog()) { printJob.print(); } else { isOK = false; } } else { printJob.print(); } } catch (Exception ex) { throw new JRException( EXCEPTION_MESSAGE_KEY_ERROR_PRINTING_REPORT, null, ex); } return isOK; }
Example 18
Source File: JRPrinterAWT.java From nordpos with GNU General Public License v3.0 | 4 votes |
/** * */ 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( EXCEPTION_MESSAGE_KEY_INVALID_PAGE_RANGE, new Object[]{firstPageIndex, lastPageIndex, 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( EXCEPTION_MESSAGE_KEY_ERROR_PRINTING_REPORT, null, ex); } return isOK; }
Example 19
Source File: PrintPageDirectNew.java From haxademic with MIT License | 4 votes |
/** * Constructor: Example3 * <p> * */ public void doPrintDemo() { //--- Create a new PrinterJob object PrinterJob printJob = PrinterJob.getPrinterJob(); //--- Create a new book to add pages to Book book = new Book(); //--- Add the cover page using the default page format for this print job book.append(new ImagePage(), printJob.defaultPage()); // book.append(new IntroPage(), printJob.defaultPage()); //--- Add the document page using a landscape page format PageFormat documentPageFormat = new PageFormat(); documentPageFormat.setOrientation(PageFormat.LANDSCAPE); //documentPageFormat.add(new Copies(1)); book.append(new Document(), documentPageFormat); //--- Add a third page using the same painter // book.append(new Document(), documentPageFormat); //--- Tell the printJob to use the book as the pageable object printJob.setPageable(book); //--- Show the print dialog box. If the user click the //--- print button we then proceed to print else we cancel //--- the process. // remove the print dialog and just print it! // if (printJob.printDialog()) { try { printJob.print(); } catch (Exception PrintException) { PrintException.printStackTrace(); } // } }
Example 20
Source File: PrintPageDirectNew.java From haxademic with MIT License | 2 votes |
public void sendToDefaultPrinter() { // configure the printing job & simple single-page document PrinterJob printJob = PrinterJob.getPrinterJob(); PageFormat pageFormat = printJob.defaultPage(); Paper paper = pageFormat.getPaper(); float inchWidth = 16; float inchHeight = 20; float marginWidth = 100; float marginHeight = 100; int pWidth = (int) ((inchWidth * 25.4f) * 2.835f);// quick: convert inch to mm, mm to pt int pHeight = (int) ((inchHeight * 25.4f) * 2.835f); paper.setSize(pWidth, pHeight); paper.setImageableArea(marginWidth, marginHeight, pWidth, pHeight); pageFormat.setPaper(paper); //not sure this exactly works, we should probably just scale the square to fit and we send it the correct rotation orientation //pageFormat.setOrientation(PageFormat.LANDSCAPE); // we might also be able to set attributes here Printable page = new ImagePage(); Book book = new Book(); book.append(page, pageFormat); /* Early testing at "LikeMinded Productions": PageFormat documentPageFormat = new PageFormat(); // new settings to play with Paper pape = new Paper(); pape.setSize(10000, 6000); pape.setImageableArea(0, 0, 10000, 6000); documentPageFormat.setPaper(pape); documentPageFormat.setOrientation(PageFormat.LANDSCAPE); */ printJob.setPageable(book); // use the print dialog UI or just print it! if(useDialog) { if (printJob.printDialog()) printPage(printJob); } else { printPage(printJob); } }