Java Code Examples for javax.print.DocPrintJob

The following are top voted examples for showing how to use javax.print.DocPrintJob. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: bisis-v4   File: Printer2.java   View source code 8 votes vote down vote up
@Override
public boolean print(Label label, String codePage) {
  if (psBarCode == null) {
    System.err.println("Barcode printer not found");
    return false;
  }
  try {
    byte[] bytes = label.getCommands().getBytes("cp" + codePage);
    DocPrintJob job = psBarCode.createPrintJob();
    DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
    Doc doc = new SimpleDoc(bytes, flavor, null);
    job.print(doc, null);
  } catch (Exception e) {
    e.printStackTrace();
    return false;
  }
  return true;
}
 
Example 2
Project: jdk8u-jdk   File: PrintSEUmlauts.java   View source code 6 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 3
Project: Camel   File: PrinterPrintTest.java   View source code 6 votes vote down vote up
protected void setupJavaPrint() {
    // "install" another default printer
    PrintService psDefault = mock(PrintService.class);
    when(psDefault.getName()).thenReturn("DefaultPrinter");
    when(psDefault.isDocFlavorSupported(any(DocFlavor.class))).thenReturn(Boolean.TRUE);
    PrintServiceLookup psLookup = mock(PrintServiceLookup.class);
    when(psLookup.getPrintServices()).thenReturn(new PrintService[]{psDefault});
    when(psLookup.getDefaultPrintService()).thenReturn(psDefault);
    DocPrintJob docPrintJob = mock(DocPrintJob.class);
    when(psDefault.createPrintJob()).thenReturn(docPrintJob);
    MediaTray[] trays = new MediaTray[]{
        MediaTray.TOP,
        MediaTray.MIDDLE,
        MediaTray.BOTTOM
    };
    when(psDefault.getSupportedAttributeValues(Media.class, null, null)).thenReturn(trays);
    PrintServiceLookup.registerServiceProvider(psLookup);
}
 
Example 4
Project: RipplePower   File: PrintImageOutput.java   View source code 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 5
Project: zebra-zpl   File: ZebraUtils.java   View source code 6 votes vote down vote up
/**
 * Function to print code Zpl to local zebra(usb)
 * 
 * @param zpl
 *            code Zpl to print
 * @param ip
 *            ip adress
 * @param port
 *            port
 * @throws ZebraPrintException
 *             if zpl could not be printed
 */
public static void printZpl(String zpl, String printerName) throws ZebraPrintException {
	try {

		PrintService psZebra = null;
		String sPrinterName = null;
		PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);

		for (int i = 0; i < services.length; i++) {
			PrintServiceAttribute attr = services[i].getAttribute(PrinterName.class);
			sPrinterName = ((PrinterName) attr).getValue();
			if (sPrinterName.toLowerCase().indexOf(printerName) >= 0) {
				psZebra = services[i];
				break;
			}
		}

		if (psZebra == null) {
			throw new ZebraPrintNotFoundException("Zebra printer not found : " + printerName);
		}
		DocPrintJob job = psZebra.createPrintJob();

		byte[] by = zpl.getBytes();
		DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
		Doc doc = new SimpleDoc(by, flavor, null);
		job.print(doc, null);

	} catch (PrintException e) {
		throw new ZebraPrintException("Cannot print label on this printer : " + printerName, e);
	}
}
 
Example 6
Project: wildfly-camel   File: PrinterIntegrationTest.java   View source code 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 7
Project: OpenJSharp   File: Win32PrintService.java   View source code 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new Win32PrintJob(this);
}
 
Example 8
Project: OpenJSharp   File: UnixPrintService.java   View source code 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new UnixPrintJob(this);
}
 
Example 9
Project: OpenJSharp   File: IPPPrintService.java   View source code 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
Project: OpenJSharp   File: Win32PrintService.java   View source code 5 votes vote down vote up
@Override
public DocPrintJob createPrintJob(){
    SecurityManager security = System.getSecurityManager();
    if(security != null){
        security.checkPrintJobAccess();
    }
    return new Win32PrintJob(this, peer);
}
 
Example 11
Project: jdk8u-jdk   File: Win32PrintService.java   View source code 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new Win32PrintJob(this);
}
 
Example 12
Project: jdk8u-jdk   File: UnixPrintService.java   View source code 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new UnixPrintJob(this);
}
 
Example 13
Project: jdk8u-jdk   File: IPPPrintService.java   View source code 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 14
Project: openjdk-jdk10   File: UnixPrintService.java   View source code 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new UnixPrintJob(this);
}
 
Example 15
Project: openjdk-jdk10   File: IPPPrintService.java   View source code 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
Project: openjdk-jdk10   File: Win32PrintService.java   View source code 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new Win32PrintJob(this);
}
 
Example 17
Project: openjdk-jdk10   File: PrintSEUmlauts.java   View source code 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
Project: openjdk9   File: UnixPrintService.java   View source code 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new UnixPrintJob(this);
}
 
Example 19
Project: openjdk9   File: IPPPrintService.java   View source code 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 20
Project: openjdk9   File: Win32PrintService.java   View source code 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new Win32PrintJob(this);
}
 
Example 21
Project: openjdk9   File: PrintSEUmlauts.java   View source code 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
Project: MedicalRS   File: PrintBillFile.java   View source code 5 votes vote down vote up
/**
   *
   * @param path
   * @throws PrintException
   * @throws IOException
   */
  public void print(String path) throws PrintException, IOException {
  String defaultPrinter =lookupDefaultPrintService().getName();
          showMessageDialog(null,"Default printer: " + defaultPrinter);

  PrintService service = lookupDefaultPrintService();
  DocFlavor flavor;
      PrintJobWatcher pjw;
      try (FileInputStream in = new FileInputStream(new File(path))) {
          PrintRequestAttributeSet  pras = new HashPrintRequestAttributeSet();
          pras.add(new Copies(1));
          flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
          Doc doc = new SimpleDoc(in, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
          DocPrintJob job = service.createPrintJob();
          pjw = new PrintJobWatcher(job);
          job.print(doc, pras);
          pjw.waitForDone();
      }

  // send FF to eject the page
  InputStream ff = new ByteArrayInputStream("\f".getBytes());
  Doc docff = new SimpleDoc(ff, flavor, null);
  DocPrintJob jobff = service.createPrintJob();
  pjw = new PrintJobWatcher(jobff);
  jobff.print(docff, null);
  pjw.waitForDone();
}
 
Example 23
Project: accounting_Soft   File: Printer.java   View source code 5 votes vote down vote up
/**
 *
 * @param g Graphic class
 * @param pf page format
 * @param page page count
 * @return 1
 * @throws PrinterException
 *
 * This methos print to pdf
 */
@Override
public int print(Graphics g, PageFormat pf, int page) throws
        PrinterException {

    DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PAGEABLE;
    PrintRequestAttributeSet patts = new HashPrintRequestAttributeSet();
    patts.add(Sides.DUPLEX);
    PrintService[] ps = PrintServiceLookup.lookupPrintServices(flavor, patts);
    if (ps.length == 0) {
        //
    }
    //System.out.println("Available printers: " + Arrays.asList(ps));
    PrintService myService = null;
    for (PrintService printService : ps) {
        if (printService.getName().equals("Your printer name")) {
            myService = printService;
            break;
        }
    }
    if (myService == null) {
        //
    }
    try (FileInputStream fis = new FileInputStream(file)) {
        Doc pdfDoc = new SimpleDoc(fis, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
        DocPrintJob printJob = myService.createPrintJob();
        printJob.print(pdfDoc, new HashPrintRequestAttributeSet());
    } catch (Exception e) {
        e.printStackTrace();
        throw new PrinterException("File Not Found!");
    }
    return 1;
}
 
Example 24
Project: jdk8u_jdk   File: Win32PrintService.java   View source code 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new Win32PrintJob(this);
}
 
Example 25
Project: jdk8u_jdk   File: UnixPrintService.java   View source code 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new UnixPrintJob(this);
}
 
Example 26
Project: jdk8u_jdk   File: IPPPrintService.java   View source code 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 27
Project: jdk8u_jdk   File: PrintSEUmlauts.java   View source code 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 28
Project: lookaside_java-1.8.0-openjdk   File: Win32PrintService.java   View source code 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new Win32PrintJob(this);
}
 
Example 29
Project: lookaside_java-1.8.0-openjdk   File: UnixPrintService.java   View source code 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new UnixPrintJob(this);
}
 
Example 30
Project: lookaside_java-1.8.0-openjdk   File: IPPPrintService.java   View source code 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 31
Project: lookaside_java-1.8.0-openjdk   File: PrintSEUmlauts.java   View source code 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 32
Project: javify   File: PrintJobAttributeEvent.java   View source code 5 votes vote down vote up
/**
 * Constructs a <code>PrintJobAttributeEvent</code> object.
 *
 * @param source the source of this event
 * @param attributes the attribute changes being reported
 */
public PrintJobAttributeEvent(DocPrintJob source,
                              PrintJobAttributeSet attributes)
{
  super(source);
  this.attributes = attributes;
}
 
Example 33
Project: code-similarity   File: PrintPostScript.java   View source code 5 votes vote down vote up
public void print() throws IOException, PrintException {
    
    DocFlavor inputFlavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8;
    
    // Lookup a print factory to convert from desired input to output.
    StreamPrintServiceFactory[] psfactories =
        StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
            inputFlavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());
    if (psfactories.length == 0) {
        System.err.println("Ack! No StreamPrintFactory found for this job!");
    }
    StreamPrintService printService = 
        psfactories[0].getPrintService(new FileOutputStream("demo.ps"));
    PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
    attrs.add(OrientationRequested.LANDSCAPE);
    attrs.add(MediaSizeName.NA_LETTER);
    attrs.add(new Copies(1));
    attrs.add(new JobName(INPUT_FILE_NAME, null));

    InputStream is = getClass().getResourceAsStream(INPUT_FILE_NAME);
    if (is == null) {
        throw new NullPointerException(
            "Input Stream is null: file not found?");
    }
    Doc doc = new SimpleDoc(is, inputFlavor, null);
    
    DocPrintJob printJob = printService.createPrintJob();
    printJob.print(doc, attrs);
}
 
Example 34
Project: code-similarity   File: PrintServiceDemo.java   View source code 5 votes vote down vote up
/** Print a file by name 
 * @throws IOException
 * @throws PrintException 
 */
public void print(String fileName) throws IOException, PrintException {
    System.out.println("PrintServiceDemo.print(): Printing " + fileName);
    DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    //aset.add(MediaSize.NA.LETTER);
    aset.add(MediaSizeName.NA_LETTER);
    //aset.add(new JobName(INPUT_FILE_NAME, null));
    PrintService[] pservices = 
        PrintServiceLookup.lookupPrintServices(flavor, aset);
    int i;
    switch(pservices.length) {
    case 0:
        System.err.println(0);
        JOptionPane.showMessageDialog(PrintServiceDemo.this,
            "Error: No PrintService Found", "Error", 
            JOptionPane.ERROR_MESSAGE);
        return;
    case 1:
        i = 0;    // Only one printer, use it.
        break;
    default:
        i = JOptionPane.showOptionDialog(this, 
            "Pick a printer", "Choice", 
            JOptionPane.OK_OPTION, JOptionPane.QUESTION_MESSAGE, 
            null, pservices, pservices[0]);
        break;
    }
    DocPrintJob pj = pservices[i].createPrintJob();
    InputStream is = getClass().getResourceAsStream(INPUT_FILE_NAME);
    if (is == null) {
        throw new NullPointerException("Input Stream is null: file not found?");
    }
    Doc doc = new SimpleDoc(is, flavor, null);
    
    pj.print(doc, aset);
}
 
Example 35
Project: Camel   File: PrinterOperations.java   View source code 5 votes vote down vote up
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);
}
 
Example 36
Project: Camel   File: PrinterPrintTest.java   View source code 5 votes vote down vote up
@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));
}
 
Example 37
Project: jvm-stm   File: PrintJobAttributeEvent.java   View source code 5 votes vote down vote up
/**
 * Constructs a <code>PrintJobAttributeEvent</code> object.
 * 
 * @param source the source of this event
 * @param attributes the attribute changes being reported
 */
public PrintJobAttributeEvent(DocPrintJob source,
                              PrintJobAttributeSet attributes)
{
  super(source);
  this.attributes = attributes;
}
 
Example 38
Project: infobip-open-jdk-8   File: Win32PrintService.java   View source code 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new Win32PrintJob(this);
}
 
Example 39
Project: infobip-open-jdk-8   File: UnixPrintService.java   View source code 5 votes vote down vote up
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new UnixPrintJob(this);
}
 
Example 40
Project: infobip-open-jdk-8   File: IPPPrintService.java   View source code 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);
}