use of java.awt.print.PrinterException in project jdk8u_jdk by JetBrains.
the class LinearGradientPrintingTest method createUI.
public static void createUI() {
f = new JFrame("LinearGradient Printing Test");
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
final LinearGradientPrintingTest gpt = new LinearGradientPrintingTest();
Container c = f.getContentPane();
c.add(BorderLayout.CENTER, gpt);
final JButton print = new JButton("Print");
print.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(gpt);
final boolean doPrint = job.printDialog();
if (doPrint) {
try {
job.print();
} catch (PrinterException ex) {
throw new RuntimeException(ex);
}
}
}
});
c.add(print, BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
}
use of java.awt.print.PrinterException in project jdk8u_jdk by JetBrains.
the class SetPrintServiceTest method main.
public static void main(String[] args) {
PrintServiceStub service = new PrintServiceStub("CustomPrintService");
PrinterJob printerJob = PrinterJob.getPrinterJob();
try {
printerJob.setPrintService(service);
System.out.println("Test Passed");
} catch (PrinterException e) {
throw new RuntimeException("Test FAILED", e);
}
}
use of java.awt.print.PrinterException in project ACS by ACS-Community.
the class PrintUtil method printPDF.
//
// -- PRIVATE METHODS ---------------------------------------------
//
private void printPDF(String name, Printable printable) {
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(MediaSizeName.ISO_A4);
aset.add(OrientationRequested.PORTRAIT);
PrintService service = findPrinterService(flavor, aset);
Assertion.assertTrue(service != null, "service != null");
PrinterJob pj = PrinterJob.getPrinterJob();
try {
pj.setPrintService(service);
pj.setPrintable(printable);
pj.pageDialog(aset);
pj.print(aset);
} catch (PrinterException e) {
Log log = LogFactory.getLog(PrintUtil.class);
log.warn("The component " + name + " could not be printed");
}
}
use of java.awt.print.PrinterException 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.PrinterException in project jdk8u_jdk by JetBrains.
the class RasterPrinterJob method getPrintService.
/**
* Returns the service (printer) for this printer job.
* Implementations of this class which do not support print services
* may return null;
* @return the service for this printer job.
*
*/
public PrintService getPrintService() {
if (myService == null) {
PrintService svc = PrintServiceLookup.lookupDefaultPrintService();
if (svc != null && svc.isDocFlavorSupported(DocFlavor.SERVICE_FORMATTED.PAGEABLE)) {
try {
setPrintService(svc);
myService = svc;
} catch (PrinterException e) {
}
}
if (myService == null) {
PrintService[] svcs = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
if (svcs.length > 0) {
try {
setPrintService(svcs[0]);
myService = svcs[0];
} catch (PrinterException e) {
}
}
}
}
return myService;
}
Aggregations