Search in sources :

Example 6 with HashPrintRequestAttributeSet

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());
}
Also used : HashDocAttributeSet(javax.print.attribute.HashDocAttributeSet) DocPrintJob(javax.print.DocPrintJob) StreamPrintService(javax.print.StreamPrintService) SimpleDoc(javax.print.SimpleDoc) FileOutputStream(java.io.FileOutputStream) PrintJobAdapter(javax.print.event.PrintJobAdapter) DocFlavor(javax.print.DocFlavor) StreamPrintServiceFactory(javax.print.StreamPrintServiceFactory) PrintJobEvent(javax.print.event.PrintJobEvent) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Example 7 with 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]));
    //
    }
}
Also used : Attribute(javax.print.attribute.Attribute) DocFlavor(javax.print.DocFlavor) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) JDialog(javax.swing.JDialog) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) PrintService(javax.print.PrintService) ServiceUIFactory(javax.print.ServiceUIFactory)

Example 8 with HashPrintRequestAttributeSet

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;
}
Also used : FileOutputStream(java.io.FileOutputStream) StreamPrintService(javax.print.StreamPrintService) DocFlavor(javax.print.DocFlavor) StreamPrintServiceFactory(javax.print.StreamPrintServiceFactory) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 9 with HashPrintRequestAttributeSet

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;
}
Also used : HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Example 10 with HashPrintRequestAttributeSet

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();
    }
}
Also used : SimpleDoc(javax.print.SimpleDoc) SimpleDoc(javax.print.SimpleDoc) Doc(javax.print.Doc) DocPrintJob(javax.print.DocPrintJob) DocFlavor(javax.print.DocFlavor) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) IOException(java.io.IOException) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintService(javax.print.PrintService)

Aggregations

HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)40 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)28 PrinterJob (java.awt.print.PrinterJob)16 PrintService (javax.print.PrintService)13 IOException (java.io.IOException)12 JobName (javax.print.attribute.standard.JobName)12 PrinterException (java.awt.print.PrinterException)10 File (java.io.File)9 DocFlavor (javax.print.DocFlavor)9 Copies (javax.print.attribute.standard.Copies)9 DocPrintJob (javax.print.DocPrintJob)8 Attribute (javax.print.attribute.Attribute)7 SimpleDoc (javax.print.SimpleDoc)6 PageFormat (java.awt.print.PageFormat)5 PrintException (javax.print.PrintException)5 PrintRequestAttribute (javax.print.attribute.PrintRequestAttribute)5 PrintServiceAttributeSet (javax.print.attribute.PrintServiceAttributeSet)4 Destination (javax.print.attribute.standard.Destination)4 java.awt.print (java.awt.print)3 Printable (java.awt.print.Printable)3