Search in sources :

Example 6 with PrinterException

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);
}
Also used : Container(java.awt.Container) JFrame(javax.swing.JFrame) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) PrinterException(java.awt.print.PrinterException) AbstractAction(javax.swing.AbstractAction) PrinterJob(java.awt.print.PrinterJob)

Example 7 with PrinterException

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);
    }
}
Also used : PrinterException(java.awt.print.PrinterException) PrinterJob(java.awt.print.PrinterJob)

Example 8 with PrinterException

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");
    }
}
Also used : Log(org.apache.commons.logging.Log) PrinterException(java.awt.print.PrinterException) DocFlavor(javax.print.DocFlavor) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintService(javax.print.PrintService) PrinterJob(java.awt.print.PrinterJob)

Example 9 with PrinterException

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);
        }
    }
}
Also used : PageFormat(java.awt.print.PageFormat) PrinterException(java.awt.print.PrinterException) Cursor(java.awt.Cursor) PrinterJob(java.awt.print.PrinterJob)

Example 10 with PrinterException

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;
}
Also used : PrinterException(java.awt.print.PrinterException) PrintService(javax.print.PrintService) StreamPrintService(javax.print.StreamPrintService)

Aggregations

PrinterException (java.awt.print.PrinterException)27 PrinterJob (java.awt.print.PrinterJob)15 PageFormat (java.awt.print.PageFormat)11 PrintService (javax.print.PrintService)8 Printable (java.awt.print.Printable)5 StreamPrintService (javax.print.StreamPrintService)5 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)5 HeadlessException (java.awt.HeadlessException)4 File (java.io.File)4 IOException (java.io.IOException)4 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)4 Container (java.awt.Container)3 ActionEvent (java.awt.event.ActionEvent)3 Paper (java.awt.print.Paper)3 PrintException (javax.print.PrintException)3 AbstractAction (javax.swing.AbstractAction)3 JButton (javax.swing.JButton)3 JFrame (javax.swing.JFrame)3 Graphics2D (java.awt.Graphics2D)2 Rectangle (java.awt.Rectangle)2