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