use of javax.print.attribute.HashPrintRequestAttributeSet in project jdk8u_jdk by JetBrains.
the class PrintSEUmlauts method main.
public static void main(String[] args) throws Exception {
GraphicsEnvironment.getLocalGraphicsEnvironment();
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
String mime = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();
StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, mime);
if (factories.length == 0) {
System.out.println("No print service found.");
return;
}
FileOutputStream output = new FileOutputStream("out.ps");
StreamPrintService service = factories[0].getPrintService(output);
SimpleDoc doc = new SimpleDoc(new PrintSEUmlauts(), DocFlavor.SERVICE_FORMATTED.PRINTABLE, new HashDocAttributeSet());
DocPrintJob job = service.createPrintJob();
job.addPrintJobListener(new PrintJobAdapter() {
@Override
public void printJobCompleted(PrintJobEvent pje) {
testPrintAndExit();
}
});
job.print(doc, new HashPrintRequestAttributeSet());
}
use of javax.print.attribute.HashPrintRequestAttributeSet 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.HashPrintRequestAttributeSet in project adempiere by adempiere.
the class ReportEngine method createPS.
// createPS
/**
* Write PostScript to writer
* @param os output stream
* @return true if success
*/
public boolean createPS(OutputStream os) {
try {
String outputMimeType = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();
DocFlavor docFlavor = DocFlavor.SERVICE_FORMATTED.PAGEABLE;
StreamPrintServiceFactory[] spsfactories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(docFlavor, outputMimeType);
if (spsfactories.length == 0) {
log.log(Level.SEVERE, "(fos) - No StreamPrintService");
return false;
}
// just use first one - sun.print.PSStreamPrinterFactory
// System.out.println("- " + spsfactories[0]);
StreamPrintService sps = spsfactories[0].getPrintService(os);
// get format
if (m_layout == null)
layout();
// print it
sps.createPrintJob().print(m_layout.getPageable(false), new HashPrintRequestAttributeSet());
//
os.flush();
//following 2 line for backward compatibility
if (os instanceof FileOutputStream)
((FileOutputStream) os).close();
} catch (Exception e) {
log.log(Level.SEVERE, "(fos)", e);
}
return false;
}
use of javax.print.attribute.HashPrintRequestAttributeSet 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;
}
use of javax.print.attribute.HashPrintRequestAttributeSet in project adempiere by adempiere.
the class POSClientSide method printOtherOS.
/**
* Print Other S.O
* @param fis
* @return void
*/
private void printOtherOS(FileInputStream fis) {
DocFlavor docFormat = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc document = new SimpleDoc(fis, docFormat, null);
PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();
PrintService[] listsPrintService = PrintServiceLookup.lookupPrintServices(docFormat, attributeSet);
try {
DocPrintJob printJob = null;
for (int x = 0; x < listsPrintService.length; x++) {
if (listsPrintService[x].getName().equals(m_Print)) {
printJob = listsPrintService[x].createPrintJob();
}
}
printJob.print(document, attributeSet);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations