Java 8 PrinterJob - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 PrinterJob class.

This code example shows how to use the following methods:print, printDialog, setPrintable
 
  /** 
   * Shows the print dialog. 
   */ 
  public void printDialog() { 
    if (m_PrinterJob.printDialog()) {
      m_PrinterJob.setPrintable(this,m_PageFormat);
      try { 
	m_PrinterJob.print();
      } 
      catch (PrinterException printerException) {
	m_PageStartY = 0;
	m_PageEndY = 0;
	m_CurrentPage = -1;
	System.out.println("Error Printing Document");
      } 
    } 
  } 
 
  /** 
6
CodeRank
This code example shows how to use the following methods:printDialog, setCopies, setJobName, setPageable
    } 
 
    private void initializePrinterJob() { 
        if (this.printerJob == null) {
            printerJob = PrinterJob.getPrinterJob();
            printerJob.setJobName("FOP Document");
            printerJob.setCopies(copies);
            if (System.getProperty("dialog") != null) {
                if (!printerJob.printDialog()) {
                    throw new RuntimeException(
                            "Printing cancelled by operator"); 
                } 
            } 
            printerJob.setPageable(this);
        } 
    } 
 
    private void setRendererOptions() { 
        Map rendererOptions = getUserAgent().getRendererOptions();
 
5
CodeRank
This code example shows how to use the following methods:defaultPage, print, printDialog, setPrintable
 
    /// Prints out the text display area 
    public void doPrint( int i ) {
        if ( printer == null ) {
            printer = PrinterJob.getPrinterJob();
            page = printer.defaultPage();
        } 
        printMode = i;
        printer.setPrintable( fc, page );
 
        if ( printer.printDialog() ) {
            try { 
                printer.print();
            } 
            catch ( Exception e ) {
                f2dt.fireChangeStatus( "ERROR: Printing Failed; See Stack Trace", true );
            } 
        } 
    } 
 
5
CodeRank
This code example shows how to use the following methods:getPrintService, setPrintService
     * @param printJob 
     *            the print job to affect 
     */ 
    private ForcedAcceptPrintService(PrinterJob printJob) {
        this.thePrintJob = printJob;
        this.delegate = printJob.getPrintService();
 
        try { 
            thePrintJob.setPrintService(this);
            // replace the private PrintService field on the PrintJob instance with a reference 
            // to our replacement PrintService so that we can intercept calls to getAttributes(). 
            // it is expected that the first thing the PrintJob will do is check it's PrintService's 
            // PrinterIsAcceptingJobs attribute, at which point we'll force it to think it is accepting 
            // jobs and restore the PrintService to the original instance to get out of the way. 
            // The only real requirement is that the PrintJob does not cast the PrintService 
            // to it's expected type until after it has checked the PrinterIsAcceptingJobs 
            // attribute. 
 
        } catch (PrinterException e) {
            AuditLog.logError(LOGGER, e, "Set Print Service"); //$NON-NLS-1$
4
CodeRank
This code example shows how to use the following methods:print, printDialog, setPrintable
    /** 
     * A private method, printDialog(), displays the print dialog and initiates 
     * printing in response to user input. 
     */ 
    private void printDialog() { 
        if (pJob.printDialog()) {
            pJob.setPrintable(this, pFormat);
            try { 
                pJob.print();
            } 
            catch (PrinterException printerException) {
                pageStartY = 0;
                pageEndY = 0;
                currentPage = -1;
                Log.error("Error Printing Document",printerException);
            } 
        } 
    } 
 
 
4
CodeRank
This code example shows how to use the following methods:defaultPage
		return true; 
	} 
 
	PageFormat getPageFormat() {
		if (pageFormat == null) {
			pageFormat = printerJob.defaultPage();
			String pageSettings = ResourceController.getResourceController().getProperty("pageSettings", null);
			if(pageSettings == null){
				return pageFormat;
			} 
			ParsePosition pos = new ParsePosition(0);
			NumberFormat parser = DecimalFormat.getInstance(Locale.US);
			Number pageFormatWidth = parser.parse(pageSettings, pos);
			if(pos.getErrorIndex() != -1 || pageFormatWidth == null)
				return pageFormat;
			pos.setIndex(pos.getIndex()+1);
			Number pageFormatHeight = parser.parse(pageSettings, pos);
			if(pos.getErrorIndex() != -1 || pageFormatHeight == null)
				return pageFormat;
			pos.setIndex(pos.getIndex()+1);
4
CodeRank
This code example shows how to use the following methods:cancel
 
	public int print (Graphics g, int page) throws PrinterException {
		int pageCount=getNumberOfPages();
		//System.out.println(page+"/"+(pageCount-1)); 
		if (page<pageCount){
			if (jr!=null&&jr.getJob().isCanceled()) printerJob.cancel();
			Graphics2D g2 = (Graphics2D) g;
			AffineTransform svgTransform=g2.getTransform();
			Color svgColor=g2.getColor();
			Stroke svgStroke=g2.getStroke();
 
			g2.transform(printableParams.getTransform());
			//System.out.println("Print transform="+printableParams.getTransform()+" zx="+printableParams.getTotalZoomX()+", zy="+printableParams.getTotalZoomY()); 
			g2.setStroke(spreadSheetStroke);
			g2.setColor(spreadSheetColor);
 
			printMain(g2,page);
 
			g2.setColor(svgColor);
			g2.setStroke(svgStroke);

3
CodeRank
See Code Examples for Java 8 PrinterJob Methods: