protected final int getMaxPageAttrib() { if (attributes != null) { SunMinMaxPage s = (SunMinMaxPage)attributes.get(SunMinMaxPage.class); if (s != null) { return s.getMax(); } } Pageable pageable = getPageable(); if (pageable != null) { int numPages = pageable.getNumberOfPages(); if (numPages <= Pageable.UNKNOWN_NUMBER_OF_PAGES) { numPages = MAX_UNKNOWN_PAGES; } return ((numPages == 0) ? 1 : numPages); } return Integer.MAX_VALUE; }
public void pageableJob(Pageable pageable) throws PrintException { try { synchronized(this) { if (job != null) { // shouldn't happen throw new PrintException("already printing"); } else { job = new PSPrinterJob(); } } job.setPrintService(getPrintService()); job.setCopies(copies); job.setJobName(jobName); job.setPageable(pageable); job.print(reqAttrSet); notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE); return; } catch (PrinterException pe) { notifyEvent(PrintJobEvent.JOB_FAILED); throw new PrintException(pe); } finally { printReturned = true; notifyEvent(PrintJobEvent.NO_MORE_EVENTS); } }
public boolean print(Pageable document) { if (pj != null) { pj.setPageable(document); if (pj.printDialog()) { try { pj.print(); return true; } catch (PrinterException pe) { OutputController.getLogger().log(OutputController.Level.ERROR_ALL, "Could not print: " + pe); OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, pe); return false; } } } else showWarning(); return false; }
/** * Print (async) * @param printerName optional printer name * @param jobName optional printer job name * @param pageable pageable * @param copies number of copies * @param withDialog if true, shows printer dialog */ static public void print (Pageable pageable, String printerName, String jobName, int copies, boolean withDialog) { if (pageable == null) return; String name = "Adempiere_"; if (jobName != null) name += jobName; // PrinterJob job = CPrinter.getPrinterJob(printerName); job.setJobName (name); job.setPageable (pageable); // Attributes HashPrintRequestAttributeSet prats = new HashPrintRequestAttributeSet(); prats.add(new Copies(copies)); // Set Orientation if (pageable.getPageFormat(0).getOrientation() == PageFormat.PORTRAIT) prats.add(OrientationRequested.PORTRAIT); else prats.add(OrientationRequested.LANDSCAPE); prats.add(new JobName(name, Language.getLoginLanguage().getLocale())); prats.add(getJobPriority(pageable.getNumberOfPages(), copies, withDialog)); // print (job, prats, withDialog, false); }
private final int getMaxPageAttrib() { if (attributes != null) { SunMinMaxPage s = (SunMinMaxPage)attributes.get(SunMinMaxPage.class); if (s != null) { return s.getMax(); } } Pageable pageable = getPageable(); if (pageable != null) { int numPages = pageable.getNumberOfPages(); if (numPages <= Pageable.UNKNOWN_NUMBER_OF_PAGES) { numPages = MAX_UNKNOWN_PAGES; } return ((numPages == 0) ? 1 : numPages); } return Integer.MAX_VALUE; }
/** * Set the range of pages from a Book to be printed. * Both 'firstPage' and 'lastPage' are zero based * page indices. If either parameter is less than * zero then the page range is set to be from the * first page to the last. */ protected void setPageRange(int firstPage, int lastPage) { if(firstPage >= 0 && lastPage >= 0) { mFirstPage = firstPage; mLastPage = lastPage; if(mLastPage < mFirstPage) mLastPage = mFirstPage; } else { mFirstPage = Pageable.UNKNOWN_NUMBER_OF_PAGES; mLastPage = Pageable.UNKNOWN_NUMBER_OF_PAGES; } }
public void pageableJob(Pageable pageable) throws PrintException { // a general hint for this code here: The PrintJob implementation (WPrinterJob) in the Oracle // JRE implements SunPrinterJobService - which we don't here. Unfortunately this is used as a hint // to distinguish between the build-in printer service and custom printer services. So for the RasterPrinterJob // this implementation of the Win32PrintJob is a custom print job! That's why several methods of // RasterPrintJob(which only apply to the SunPrinterJobService otherwise) had to be moved here. // This includes the attribute resolving and the media patch for instance. try { PrintDocument printDocument = createPrintDocument( ); pageable = patchMedia( pageable ); printDocument.add_QueryPageSettings(new QueryPageSettingsEventHandler(new QueryPage( pageable, printColor, mediaTray ) ) ); printDocument.add_PrintPage(new PrintPageEventHandler(new PrintPage(pageable))); printDocument.Print(); if(printerException != null){ throw printerException; } //TODO throw exception on Cancel notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE); return; } catch (PrinterException pe) { notifyEvent(PrintJobEvent.JOB_FAILED); throw new PrintException(pe); } finally { printReturned = true; notifyEvent(PrintJobEvent.NO_MORE_EVENTS); } }
/** * This sets the pages that are to be printed. * * @param pageable The pages to be printed, which may not be <code>null</code>. */ public void setPageable(Pageable pageable) { if( pageable == null ) throw new NullPointerException("Pageable cannot be null."); this.pageable = pageable; }
/** * Can we archive the document? * @param layout layout * @return true if can be archived */ public static boolean isValid (LayoutEngine layout) { return (layout != null && Document.isValid((Pageable)layout) && layout.getNumberOfPages() > 0); }
/** * Print Async * @param pageable pageable * @param prats print attribure set */ static public void print (Pageable pageable, PrintRequestAttributeSet prats) { PrinterJob job = CPrinter.getPrinterJob(); job.setPageable(pageable); print (job, prats, true, false); }
public static File getPDFAsFile(String filename, Pageable pageable) { final File result = new File(filename); try { writePDF(pageable, new FileOutputStream(result)); } catch (Exception e) { e.printStackTrace(); } return result; }
public static byte[] getPDFAsArray(Pageable pageable) { try { ByteArrayOutputStream output = new ByteArrayOutputStream(10240); writePDF(pageable, output); return output.toByteArray(); } catch (Exception e) { e.printStackTrace(); } return null; }
@Override public void setPageable(Pageable document) throws NullPointerException { if (document == null) { throw new NullPointerException("Pageable cannot be null."); } this.pageable = document; }
/** * Return the Pageable describing the pages to be printed. */ protected Pageable getPageable() { return mDocument; }