use of javax.print.DocPrintJob in project camel by apache.
the class PrinterOperations method print.
public void print(Doc doc, String jobName) throws PrintException {
// we need create a new job for each print
DocPrintJob job = getPrintService().createPrintJob();
PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet(printRequestAttributeSet);
attrs.add(new JobName(jobName, Locale.getDefault()));
job.print(doc, attrs);
}
use of javax.print.DocPrintJob in project camel by apache.
the class PrinterPrintTest method printerNameTest.
@Test
public void printerNameTest() throws Exception {
if (isAwtHeadless()) {
return;
}
// setup javax.print
PrintService ps1 = mock(PrintService.class);
when(ps1.getName()).thenReturn("MyPrinter\\\\remote\\printer1");
when(ps1.isDocFlavorSupported(any(DocFlavor.class))).thenReturn(Boolean.TRUE);
boolean res1 = PrintServiceLookup.registerService(ps1);
assertTrue("The Remote PrintService #1 should be registered.", res1);
DocPrintJob job1 = mock(DocPrintJob.class);
when(ps1.createPrintJob()).thenReturn(job1);
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:start1").to("lpr://remote/printer1?sendToPrinter=true");
}
});
context.start();
template.sendBody("direct:start1", "Hello Printer 1");
context.stop();
verify(job1, times(1)).print(any(Doc.class), any(PrintRequestAttributeSet.class));
}
use of javax.print.DocPrintJob in project jdk8u_jdk by JetBrains.
the class RasterPrinterJob method spoolToService.
/*
* Services we don't recognize as built-in services can't be
* implemented as subclasses of PrinterJob, therefore we create
* a DocPrintJob from their service and pass a Doc representing
* the application's printjob
*/
// MacOSX - made protected so subclasses can reference it.
protected void spoolToService(PrintService psvc, PrintRequestAttributeSet attributes) throws PrinterException {
if (psvc == null) {
throw new PrinterException("No print service found.");
}
DocPrintJob job = psvc.createPrintJob();
Doc doc = new PageableDoc(getPageable());
if (attributes == null) {
attributes = new HashPrintRequestAttributeSet();
}
try {
job.print(doc, attributes);
} catch (PrintException e) {
throw new PrinterException(e.toString());
}
}
Aggregations