use of javax.print.attribute.PrintRequestAttributeSet 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.PrintRequestAttributeSet 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.PrintRequestAttributeSet 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!");
}
}
use of javax.print.attribute.PrintRequestAttributeSet in project adempiere by adempiere.
the class PrintUtil method dump.
// dump
/**
* Dump Stream Print Services
* @param docFlavor flavor
*/
public static void dump(DocFlavor docFlavor) {
System.out.println();
System.out.println("DocFlavor=" + docFlavor);
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
PrintService[] pss = PrintServiceLookup.lookupPrintServices(docFlavor, pras);
for (int i = 0; i < pss.length; i++) {
PrintService ps = pss[i];
System.out.println("- " + ps);
System.out.println(" Factory=" + ps.getServiceUIFactory());
ServiceUIFactory uiF = pss[i].getServiceUIFactory();
if (uiF != null) {
System.out.println("about");
JDialog about = (JDialog) uiF.getUI(ServiceUIFactory.ABOUT_UIROLE, ServiceUIFactory.JDIALOG_UI);
about.setVisible(true);
System.out.println("admin");
JDialog admin = (JDialog) uiF.getUI(ServiceUIFactory.ADMIN_UIROLE, ServiceUIFactory.JDIALOG_UI);
admin.setVisible(true);
System.out.println("main");
JDialog main = (JDialog) uiF.getUI(ServiceUIFactory.MAIN_UIROLE, ServiceUIFactory.JDIALOG_UI);
main.setVisible(true);
System.out.println("reserved");
JDialog res = (JDialog) uiF.getUI(ServiceUIFactory.RESERVED_UIROLE, ServiceUIFactory.JDIALOG_UI);
res.setVisible(true);
}
//
DocFlavor[] dfs = pss[i].getSupportedDocFlavors();
System.out.println(" - Supported Doc Flavors");
for (int j = 0; j < dfs.length; j++) System.out.println(" -> " + dfs[j]);
// Attribute
Class[] attCat = pss[i].getSupportedAttributeCategories();
System.out.println(" - Supported Attribute Categories");
for (int j = 0; j < attCat.length; j++) System.out.println(" -> " + attCat[j].getName() + " = " + pss[i].getDefaultAttributeValue((Class<? extends Attribute>) attCat[j]));
//
}
}
use of javax.print.attribute.PrintRequestAttributeSet in project adempiere by adempiere.
the class CPaper method getPrintRequestAttributeSet.
// pageSetupDialog
/**
* Return Print Request Attributes
* @return PrintRequestAttributeSet
*/
public PrintRequestAttributeSet getPrintRequestAttributeSet() {
PrintRequestAttributeSet pratts = new HashPrintRequestAttributeSet();
// media-printable-area = (25.4,25.4)->(165.1,228.6)mm - class javax.print.attribute.standard.MediaPrintableArea
pratts.add(getMediaPrintableArea());
// orientation-requested = landscape - class javax.print.attribute.standard.OrientationRequested
if (isLandscape())
pratts.add(OrientationRequested.LANDSCAPE);
else
pratts.add(OrientationRequested.PORTRAIT);
return pratts;
}
Aggregations