Search in sources :

Example 6 with PrinterJob

use of java.awt.print.PrinterJob 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 7 with PrinterJob

use of java.awt.print.PrinterJob in project jdk8u_jdk by JetBrains.

the class PageDlgApp method main.

public static void main(String[] args) throws Exception {
    String[] instructions = { "Visual inspection of the dialog is needed. ", "It should be a Printer Job Setup Dialog", "Do nothing except Cancel", "You must NOT press OK" };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null, instructions, "information", JOptionPane.INFORMATION_MESSAGE);
    });
    PrinterJob pj = PrinterJob.getPrinterJob();
    PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
    pSet.add(DialogTypeSelection.NATIVE);
    if ((pj.pageDialog(pSet)) != null) {
        throw new RuntimeException("PrinterJob.pageDialog(PrintRequestAttributeSet)" + " does not return null when dialog is cancelled");
    }
}
Also used : HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrinterJob(java.awt.print.PrinterJob) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Example 8 with PrinterJob

use of java.awt.print.PrinterJob in project jdk8u_jdk by JetBrains.

the class ImageableAreaTest method printWithCustomImageareaSize.

private static void printWithCustomImageareaSize() {
    final JTable table = createAuthorTable(18);
    PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
    printAttributes.add(DialogTypeSelection.NATIVE);
    printAttributes.add(new Copies(1));
    printAttributes.add(new MediaPrintableArea(0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
    Printable printable = table.getPrintable(JTable.PrintMode.NORMAL, new MessageFormat("Author Table"), new MessageFormat("Page - {0}"));
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(printable);
    boolean printAccepted = job.printDialog(printAttributes);
    if (printAccepted) {
        try {
            job.print(printAttributes);
            closeFrame();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        throw new RuntimeException("User cancels the printer job!");
    }
}
Also used : MediaPrintableArea(javax.print.attribute.standard.MediaPrintableArea) MessageFormat(java.text.MessageFormat) Copies(javax.print.attribute.standard.Copies) JTable(javax.swing.JTable) Printable(java.awt.print.Printable) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrinterException(java.awt.print.PrinterException) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrinterJob(java.awt.print.PrinterJob)

Example 9 with PrinterJob

use of java.awt.print.PrinterJob in project jdk8u_jdk by JetBrains.

the class RadialGradientPrintingTest method createUI.

public static void createUI() {
    f = new JFrame("RadialGradient Printing Test");
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    final RadialGradientPrintingTest gpt = new RadialGradientPrintingTest();
    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 10 with PrinterJob

use of java.awt.print.PrinterJob in project jdk8u_jdk by JetBrains.

the class TexturePaintPrintingTest method printTexture.

private static void printTexture() {
    f = new JFrame("Texture Printing Test");
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    final TexturePaintPrintingTest gpt = new TexturePaintPrintingTest();
    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)

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