Search in sources :

Example 6 with DocPrintJob

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

Example 7 with DocPrintJob

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));
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Doc(javax.print.Doc) DocPrintJob(javax.print.DocPrintJob) DocFlavor(javax.print.DocFlavor) PrintService(javax.print.PrintService) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) Test(org.junit.Test)

Example 8 with DocPrintJob

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());
    }
}
Also used : PrintException(javax.print.PrintException) Doc(javax.print.Doc) PageableDoc(sun.print.PageableDoc) PrinterException(java.awt.print.PrinterException) DocPrintJob(javax.print.DocPrintJob) PageableDoc(sun.print.PageableDoc) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Aggregations

DocPrintJob (javax.print.DocPrintJob)8 DocFlavor (javax.print.DocFlavor)6 PrintService (javax.print.PrintService)5 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)5 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)5 Doc (javax.print.Doc)4 SimpleDoc (javax.print.SimpleDoc)3 FileOutputStream (java.io.FileOutputStream)2 StreamPrintServiceFactory (javax.print.StreamPrintServiceFactory)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 Test (org.junit.Test)2 BufferedImage (java.awt.image.BufferedImage)1 PageFormat (java.awt.print.PageFormat)1 Printable (java.awt.print.Printable)1 PrinterException (java.awt.print.PrinterException)1 File (java.io.File)1 IOException (java.io.IOException)1 Map (java.util.Map)1 PrintException (javax.print.PrintException)1 PrintServiceLookup (javax.print.PrintServiceLookup)1