Search in sources :

Example 11 with PrinterJob

use of java.awt.print.PrinterJob in project adempiere by adempiere.

the class PDFViewerBean method print.

public void print() {
    PrinterJob printJob = PrinterJob.getPrinterJob();
    //decoder.enableScaledPrinting(false);
    printJob.setPageable(decoder);
    final PageFormat pf = printJob.defaultPage();
    decoder.setPageFormat(pf);
    decoder.setTextPrint(PdfDecoder.TEXTGLYPHPRINT);
    printJob.setPrintable(decoder, pf);
    if (printJob.printDialog()) {
        final Cursor oldCursor = getCursor();
        try {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            printJob.print();
        } catch (PrinterException e) {
            e.printStackTrace();
        } finally {
            setCursor(oldCursor);
        }
    }
}
Also used : PageFormat(java.awt.print.PageFormat) PrinterException(java.awt.print.PrinterException) Cursor(java.awt.Cursor) PrinterJob(java.awt.print.PrinterJob)

Example 12 with PrinterJob

use of java.awt.print.PrinterJob in project adempiere by adempiere.

the class CPrinter method getPrinterJob.

//  getPrinterJob
/**
	 *  Return PrinterJob with selected printer name.
	 *  @param printerName if null, get default printer (Ini)
	 *  @return PrinterJob
	 */
public static PrinterJob getPrinterJob(String printerName) {
    PrinterJob pj = null;
    PrintService ps = null;
    try {
        pj = PrinterJob.getPrinterJob();
        //  find printer service
        if (printerName == null || printerName.length() == 0)
            printerName = Ini.getProperty(Ini.P_PRINTER);
        if (printerName != null && printerName.length() != 0) {
            //	System.out.println("CPrinter.getPrinterJob - searching " + printerName);
            for (int i = 0; i < s_services.length; i++) {
                String serviceName = s_services[i].getName();
                if (printerName.equals(serviceName)) {
                    ps = s_services[i];
                    //	System.out.println("CPrinter.getPrinterJob - found " + printerName);
                    break;
                }
            //	System.out.println("CPrinter.getPrinterJob - not: " + serviceName);
            }
        }
        try {
            if (ps != null)
                pj.setPrintService(ps);
        } catch (Exception e) {
            log.warning("Could not set Print Service: " + e.toString());
        }
        //
        PrintService psUsed = pj.getPrintService();
        if (psUsed == null)
            log.warning("Print Service not Found");
        else {
            String serviceName = psUsed.getName();
            if (printerName != null && !printerName.equals(serviceName))
                log.warning("Not found: " + printerName + " - Used: " + serviceName);
        }
    } catch (Exception e) {
        log.warning("Could not create for " + printerName + ": " + e.toString());
    }
    return pj;
}
Also used : PrinterJob(java.awt.print.PrinterJob) PrintService(javax.print.PrintService)

Example 13 with PrinterJob

use of java.awt.print.PrinterJob in project adempiere by adempiere.

the class ReportEngine method print.

//	getView
/**************************************************************************
	 * 	Print Report
	 */
public void print() {
    log.info(m_info.toString());
    if (m_layout == null)
        layout();
    //	Paper Attributes: 	media-printable-area, orientation-requested, media
    PrintRequestAttributeSet prats = m_layout.getPaper().getPrintRequestAttributeSet();
    //	add:				copies, job-name, priority
    if (m_info.isDocumentCopy() || m_info.getCopies() < 1)
        prats.add(new Copies(1));
    else
        prats.add(new Copies(m_info.getCopies()));
    Locale locale = Language.getLoginLanguage().getLocale();
    prats.add(new JobName(m_printFormat.getName(), locale));
    prats.add(PrintUtil.getJobPriority(m_layout.getNumberOfPages(), m_info.getCopies(), true));
    try {
        //	PrinterJob
        PrinterJob job = getPrinterJob(m_info.getPrinterName());
        //	job.getPrintService().addPrintServiceAttributeListener(this);
        //	no copy
        job.setPageable(m_layout.getPageable(false));
        //	Dialog
        try {
            if (m_info.isWithDialog() && !job.printDialog(prats))
                return;
        } catch (Exception e) {
            log.log(Level.WARNING, "Operating System Print Issue, check & try again", e);
            return;
        }
        //	submit
        boolean printCopy = m_info.isDocumentCopy() && m_info.getCopies() > 1;
        ArchiveEngine.get().archive(m_layout, m_info);
        PrintUtil.print(job, prats, false, printCopy);
        //	Document: Print Copies
        if (printCopy) {
            log.info("Copy " + (m_info.getCopies() - 1));
            prats.add(new Copies(m_info.getCopies() - 1));
            job = getPrinterJob(m_info.getPrinterName());
            //	job.getPrintService().addPrintServiceAttributeListener(this);
            //	Copy
            job.setPageable(m_layout.getPageable(true));
            PrintUtil.print(job, prats, false, false);
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    }
}
Also used : Locale(java.util.Locale) Copies(javax.print.attribute.standard.Copies) JobName(javax.print.attribute.standard.JobName) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) IOException(java.io.IOException) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) PrinterJob(java.awt.print.PrinterJob)

Example 14 with PrinterJob

use of java.awt.print.PrinterJob in project jgnash by ccavanaugh.

the class DynamicJasperReportPanel method pageSetupAction.

private void pageSetupAction() {
    PageFormat oldFormat = report.getPageFormat();
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat format = job.pageDialog(oldFormat);
    if (format != oldFormat) {
        report.setPageFormat(format);
        refreshReport();
    }
}
Also used : PageFormat(java.awt.print.PageFormat) PrinterJob(java.awt.print.PrinterJob)

Example 15 with PrinterJob

use of java.awt.print.PrinterJob in project jgnash by ccavanaugh.

the class ReportPrintFactory method getPageFormat.

static PageFormat getPageFormat(final BaseDynamicJasperReport report) {
    Preferences p = report.getPreferences();
    double height = p.getDouble(HEIGHT, 0);
    double width = p.getDouble(WIDTH, 0);
    int orientation = p.getInt(ORIENTATION, 0);
    double imageableHeight = p.getDouble(IMAGEABLE_HEIGHT, 0);
    double imageableWidth = p.getDouble(IMAGEABLE_WIDTH, 0);
    double imageableX = p.getDouble(IMAGEABLE_X, 0);
    double imageableY = p.getDouble(IMAGEABLE_Y, 0);
    if (height == 0 || width == 0 || imageableHeight == 0 || imageableWidth == 0) {
        return getDefaultPage();
    }
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat pf = job.defaultPage();
    pf.setOrientation(orientation);
    Paper paper = pf.getPaper();
    paper.setSize(width, height);
    paper.setImageableArea(imageableX, imageableY, imageableWidth, imageableHeight);
    pf.setPaper(paper);
    return pf;
}
Also used : PageFormat(java.awt.print.PageFormat) Paper(java.awt.print.Paper) Preferences(java.util.prefs.Preferences) PrinterJob(java.awt.print.PrinterJob)

Aggregations

PrinterJob (java.awt.print.PrinterJob)57 PrinterException (java.awt.print.PrinterException)28 PageFormat (java.awt.print.PageFormat)22 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)19 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)17 PDFPageable (org.apache.pdfbox.printing.PDFPageable)9 IOException (java.io.IOException)7 Paper (java.awt.print.Paper)6 Printable (java.awt.print.Printable)5 File (java.io.File)5 Copies (javax.print.attribute.standard.Copies)5 ActionEvent (java.awt.event.ActionEvent)4 PrintService (javax.print.PrintService)4 Container (java.awt.Container)3 Book (java.awt.print.Book)3 JobName (javax.print.attribute.standard.JobName)3 PageRanges (javax.print.attribute.standard.PageRanges)3 AbstractAction (javax.swing.AbstractAction)3 JButton (javax.swing.JButton)3 JFrame (javax.swing.JFrame)3