Search in sources :

Example 1 with NullPrintServiceException

use of qz.exception.NullPrintServiceException in project tray by qzind.

the class PrintRaw method printToPrinter.

/**
 * Constructs a {@code SimpleDoc} with the {@code commands} byte array.
 */
private void printToPrinter(PrintService service, byte[] cmds, PrintOptions.Raw rawOpts) throws PrintException {
    if (service == null) {
        throw new NullPrintServiceException("Service cannot be null");
    }
    if (cmds == null || cmds.length == 0) {
        throw new NullCommandException("No commands found to send to the printer");
    }
    SimpleDoc doc = new SimpleDoc(cmds, DocFlavor.BYTE_ARRAY.AUTOSENSE, null);
    PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
    attributes.add(new JobName(rawOpts.getJobName(Constants.RAW_PRINT), Locale.getDefault()));
    DocPrintJob printJob = service.createPrintJob();
    waitForPrint(printJob, doc, attributes);
}
Also used : JobName(javax.print.attribute.standard.JobName) NullCommandException(qz.exception.NullCommandException) NullPrintServiceException(qz.exception.NullPrintServiceException) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet)

Aggregations

HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)1 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)1 JobName (javax.print.attribute.standard.JobName)1 NullCommandException (qz.exception.NullCommandException)1 NullPrintServiceException (qz.exception.NullPrintServiceException)1