use of java.awt.print.PrinterJob 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.PrinterJob 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.PrinterJob in project jdk8u_jdk by JetBrains.
the class PrintAttributeUpdateTest method main.
public static void main(String[] args) throws Exception {
String[] instructions = { "Select Pages Range From instead of All in print dialog. ", "Then select Print" };
SwingUtilities.invokeAndWait(() -> {
JOptionPane.showMessageDialog((Component) null, instructions, "Instructions", JOptionPane.INFORMATION_MESSAGE);
});
HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
PrinterJob j = PrinterJob.getPrinterJob();
j.setPageable(new PrintAttributeUpdateTest());
as.add(DialogTypeSelection.NATIVE);
j.printDialog(as);
if (as.containsKey(PageRanges.class) == false) {
throw new RuntimeException("Print Dialog did not update " + " attribute set with page range");
}
Attribute[] attrs = as.toArray();
for (int i = 0; i < attrs.length; i++) {
System.out.println("attr " + attrs[i]);
}
j.print(as);
}
use of java.awt.print.PrinterJob in project jdk8u_jdk by JetBrains.
the class PrintCrashTest method main.
public static void main(String[] args) throws Exception {
PrinterJob printerJob = PrinterJob.getPrinterJob();
printerJob.setPrintable((graphics, pageFormat, pageIndex) -> {
if (pageIndex != 0) {
return Printable.NO_SUCH_PAGE;
} else {
Shape shape = new Rectangle(110, 110, 10, 10);
Rectangle rect = shape.getBounds();
BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(rect.width, rect.height, Transparency.BITMASK);
graphics.drawImage(image, rect.x, rect.y, rect.width, rect.height, null);
return Printable.PAGE_EXISTS;
}
});
File file = null;
try {
HashPrintRequestAttributeSet hashPrintRequestAttributeSet = new HashPrintRequestAttributeSet();
file = File.createTempFile("out", "ps");
file.deleteOnExit();
Destination destination = new Destination(file.toURI());
hashPrintRequestAttributeSet.add(destination);
printerJob.print(hashPrintRequestAttributeSet);
} finally {
if (file != null) {
file.delete();
}
}
}
use of java.awt.print.PrinterJob in project jdk8u_jdk by JetBrains.
the class PrintDialog method main.
public static void main(String[] args) throws Exception {
// instruction dialog
Frame instruction = new Frame("Verify that no native print dialog is showed");
instruction.add(new TextArea(instructions));
instruction.pack();
instruction.show();
// test begin
PrintServiceStub service = new PrintServiceStub("test");
PrintServiceLookup.registerService(service);
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintService(service);
job.printDialog();
System.out.println("test passed");
}
Aggregations