javax.print.DocPrintJob Java Examples

The following examples show how to use javax.print.DocPrintJob. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrinterOutputStream.java    From escpos-coffee with MIT License 6 votes vote down vote up
/**
 * creates one instance of PrinterOutputStream.
 * <p>
 * Create one print based on print service. Start print job linked (this)
 * output stream.
 *
 * @param printService value used to create the printer job
 * @exception IOException if an I/O error occurs.
 * @see #getPrintServiceByName(java.lang.String)
 * @see #getDefaultPrintService()
 */
public PrinterOutputStream(PrintService printService) throws IOException {

    UncaughtExceptionHandler uncaughtException = (Thread t, Throwable e) -> {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, e.getMessage(),e);
    };

    pipedInputStream = new PipedInputStream();
    super.connect(pipedInputStream);

    Runnable runnablePrint = () -> {
        try {
            DocFlavor df = DocFlavor.INPUT_STREAM.AUTOSENSE;
            Doc d = new SimpleDoc(pipedInputStream, df, null);

            DocPrintJob job = printService.createPrintJob();
            job.print(d, null);
        } catch (PrintException ex) {
            throw new RuntimeException(ex);
        }
    };

    threadPrint = new Thread(runnablePrint);
    threadPrint.setUncaughtExceptionHandler(uncaughtException);
    threadPrint.start();
}
 
Example #2
Source File: PrinterIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    PrintService psDefault = Mockito.mock(PrintService.class);
    Mockito.when(psDefault.getName()).thenReturn("DefaultPrinter");
    Mockito.when(psDefault.isDocFlavorSupported(Mockito.any(DocFlavor.class))).thenReturn(Boolean.TRUE);
    PrintServiceLookup psLookup = Mockito.mock(PrintServiceLookup.class);
    Mockito.when(psLookup.getPrintServices()).thenReturn(new PrintService[]{psDefault});
    Mockito.when(psLookup.getDefaultPrintService()).thenReturn(psDefault);
    DocPrintJob docPrintJob = Mockito.mock(DocPrintJob.class);
    Mockito.when(psDefault.createPrintJob()).thenReturn(docPrintJob);
    MediaTray[] trays = new MediaTray[]{
        MediaTray.TOP,
        MediaTray.MIDDLE,
        MediaTray.BOTTOM
    };
    Mockito.when(psDefault.getSupportedAttributeValues(Media.class, null, null)).thenReturn(trays);
    PrintServiceLookup.registerServiceProvider(psLookup);
}
 
Example #3
Source File: PrintImageOutput.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
public static boolean out(BufferedImage image) {
	try {
		DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
		PrintRequestAttributeSet requestAttributeSet = new HashPrintRequestAttributeSet();
		requestAttributeSet.add(MediaSizeName.ISO_A4);
		requestAttributeSet.add(new JobName(LSystem.applicationName + LSystem.getTime(), Locale.ENGLISH));
		PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, requestAttributeSet);
		PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
		PrintService service = ServiceUI.printDialog(null, 100, 100, services, defaultService, flavor,
				requestAttributeSet);
		if (service != null) {
			DocPrintJob job = service.createPrintJob();
			SimpleDoc doc = new SimpleDoc(new BufferedImagePrintable(image), flavor, null);
			job.print(doc, requestAttributeSet);
		}
	} catch (Exception e) {
		return false;
	}
	return true;
}
 
Example #4
Source File: Java14PrintUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void printDirectly( final MasterReport report, PrintService printService ) throws PrintException,
  ReportProcessingException {
  // with that method we do not use the PrintService UI ..
  // it is up to the user to supply a valid print service that
  // supports the Pageable printing.
  if ( printService == null ) {
    printService = lookupPrintService();
  } else {
    if ( printService.isDocFlavorSupported( DocFlavor.SERVICE_FORMATTED.PAGEABLE ) == false ) {
      throw new PrintException( "The print service implementation does not support the Pageable Flavor." );
    }
  }

  PrintRequestAttributeSet attributes = Java14PrintUtil.copyConfiguration( null, report );
  attributes = Java14PrintUtil.copyAuxillaryAttributes( attributes, report );

  final PrintReportProcessor reportPane = new PrintReportProcessor( report );
  final DocPrintJob job = printService.createPrintJob();
  final SimpleDoc document = new SimpleDoc( reportPane, DocFlavor.SERVICE_FORMATTED.PAGEABLE, null );

  try {
    job.print( document, attributes );
  } finally {
    reportPane.close();
  }

}
 
Example #5
Source File: IPPPrintService.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public DocPrintJob createPrintJob() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }
    // REMIND: create IPPPrintJob
    return new UnixPrintJob(this);
}
 
Example #6
Source File: UnixPrintService.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new UnixPrintJob(this);
}
 
Example #7
Source File: Win32PrintService.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new Win32PrintJob(this);
}
 
Example #8
Source File: UnixPrintService.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new UnixPrintJob(this);
}
 
Example #9
Source File: IPPPrintService.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public DocPrintJob createPrintJob() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }
    // REMIND: create IPPPrintJob
    return new UnixPrintJob(this);
}
 
Example #10
Source File: PrintSEUmlauts.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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());
    }
 
Example #11
Source File: IPPPrintService.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public DocPrintJob createPrintJob() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }
    // REMIND: create IPPPrintJob
    return new UnixPrintJob(this);
}
 
Example #12
Source File: Win32PrintService.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new Win32PrintJob(this);
}
 
Example #13
Source File: PrintSEUmlauts.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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());
    }
 
Example #14
Source File: Win32PrintService.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new Win32PrintJob(this);
}
 
Example #15
Source File: IPPPrintService.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public DocPrintJob createPrintJob() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }
    // REMIND: create IPPPrintJob
    return new UnixPrintJob(this);
}
 
Example #16
Source File: IPPPrintService.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public DocPrintJob createPrintJob() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }
    // REMIND: create IPPPrintJob
    return new UnixPrintJob(this);
}
 
Example #17
Source File: PrintSEUmlauts.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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());
    }
 
Example #18
Source File: Win32PrintService.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new Win32PrintJob(this);
}
 
Example #19
Source File: PrintSEUmlauts.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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());
    }
 
Example #20
Source File: IPPPrintService.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public DocPrintJob createPrintJob() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }
    // REMIND: create IPPPrintJob
    return new UnixPrintJob(this);
}
 
Example #21
Source File: PrintSEUmlauts.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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());
    }
 
Example #22
Source File: IPPPrintService.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public DocPrintJob createPrintJob() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }
    // REMIND: create IPPPrintJob
    return new UnixPrintJob(this);
}
 
Example #23
Source File: Win32PrintService.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new Win32PrintJob(this);
}
 
Example #24
Source File: Win32PrintService.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new Win32PrintJob(this);
}
 
Example #25
Source File: UnixPrintService.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new UnixPrintJob(this);
}
 
Example #26
Source File: PrintServiceStub.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DocPrintJob createPrintJob() {
    return null;
}
 
Example #27
Source File: PrintServiceStub.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DocPrintJob createPrintJob() {
    return null;
}
 
Example #28
Source File: PSStreamPrintService.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public DocPrintJob createPrintJob() {
    return new PSStreamPrintJob(this);
}
 
Example #29
Source File: PSStreamPrintService.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public DocPrintJob createPrintJob() {
    return new PSStreamPrintJob(this);
}
 
Example #30
Source File: PrintServiceStub.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DocPrintJob createPrintJob() {
    return null;
}