use of javax.print.attribute.HashPrintRequestAttributeSet 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 javax.print.attribute.HashPrintRequestAttributeSet 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 javax.print.attribute.HashPrintRequestAttributeSet 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 javax.print.attribute.HashPrintRequestAttributeSet 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");
}
}
use of javax.print.attribute.HashPrintRequestAttributeSet 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!");
}
}
Aggregations