Search in sources :

Example 51 with PrinterJob

use of java.awt.print.PrinterJob in project pdfbox by apache.

the class PDFDebugger method printMenuItemActionPerformed.

private void printMenuItemActionPerformed(ActionEvent evt) {
    if (document == null) {
        return;
    }
    try {
        PrinterJob job = PrinterJob.getPrinterJob();
        job.setPageable(new PDFPageable(document));
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        PDViewerPreferences vp = document.getDocumentCatalog().getViewerPreferences();
        if (vp != null && vp.getDuplex() != null) {
            String dp = vp.getDuplex();
            if (PDViewerPreferences.DUPLEX.DuplexFlipLongEdge.toString().equals(dp)) {
                pras.add(Sides.TWO_SIDED_LONG_EDGE);
            } else if (PDViewerPreferences.DUPLEX.DuplexFlipShortEdge.toString().equals(dp)) {
                pras.add(Sides.TWO_SIDED_SHORT_EDGE);
            } else if (PDViewerPreferences.DUPLEX.Simplex.toString().equals(dp)) {
                pras.add(Sides.ONE_SIDED);
            }
        }
        if (job.printDialog(pras)) {
            job.print(pras);
        }
    } catch (PrinterException e) {
        throw new RuntimeException(e);
    }
}
Also used : PDFPageable(org.apache.pdfbox.printing.PDFPageable) COSString(org.apache.pdfbox.cos.COSString) PrinterException(java.awt.print.PrinterException) PDViewerPreferences(org.apache.pdfbox.pdmodel.interactive.viewerpreferences.PDViewerPreferences) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrinterJob(java.awt.print.PrinterJob) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet)

Example 52 with PrinterJob

use of java.awt.print.PrinterJob in project pdfbox by apache.

the class Printing method print.

/**
 * Prints the document at its actual size. This is the recommended way to print.
 */
private static void print(PDDocument document) throws IOException, PrinterException {
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPageable(new PDFPageable(document));
    job.print();
}
Also used : PDFPageable(org.apache.pdfbox.printing.PDFPageable) PrinterJob(java.awt.print.PrinterJob)

Example 53 with PrinterJob

use of java.awt.print.PrinterJob in project pdfbox by apache.

the class Printing method printWithDialog.

/**
 * Prints with a print preview dialog.
 */
private static void printWithDialog(PDDocument document) throws IOException, PrinterException {
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPageable(new PDFPageable(document));
    if (job.printDialog()) {
        job.print();
    }
}
Also used : PDFPageable(org.apache.pdfbox.printing.PDFPageable) PrinterJob(java.awt.print.PrinterJob)

Example 54 with PrinterJob

use of java.awt.print.PrinterJob in project SIMVA-SoS by SESoS.

the class ChartPanel method createChartPrintJob.

/**
 * Creates a print job for the chart.
 */
public void createChartPrintJob() {
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat pf = job.defaultPage();
    PageFormat pf2 = job.pageDialog(pf);
    if (pf2 != pf) {
        job.setPrintable(this, pf2);
        if (job.printDialog()) {
            try {
                job.print();
            } catch (PrinterException e) {
                JOptionPane.showMessageDialog(this, e);
            }
        }
    }
}
Also used : PageFormat(java.awt.print.PageFormat) PrinterException(java.awt.print.PrinterException) PrinterJob(java.awt.print.PrinterJob)

Example 55 with PrinterJob

use of java.awt.print.PrinterJob in project opt4j by felixreimann.

the class PlotFrame method _printCrossPlatform.

/**
 * Print using the cross platform dialog. FIXME: this dialog is slow and is
 * often hidden behind other windows. However, it does honor the user's
 * choice of portrait vs. landscape
 */
protected void _printCrossPlatform() {
    // Build a set of attributes
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(plot);
    if (job.printDialog(aset)) {
        try {
            job.print(aset);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Printing failed:\n" + ex.toString(), "Print Error", JOptionPane.WARNING_MESSAGE);
        }
    }
}
Also used : HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) PrinterJob(java.awt.print.PrinterJob)

Aggregations

PrinterJob (java.awt.print.PrinterJob)58 PrinterException (java.awt.print.PrinterException)29 PageFormat (java.awt.print.PageFormat)22 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)19 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)17 PDFPageable (org.apache.pdfbox.printing.PDFPageable)10 IOException (java.io.IOException)8 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