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);
}
}
}
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;
}
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);
}
}
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();
}
}
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;
}
Aggregations