Search in sources :

Example 1 with PrintProcessor

use of qz.printer.action.PrintProcessor in project tray by qzind.

the class PrintingUtilities method processPrintRequest.

/**
 * Determine print variables and send data to printer
 *
 * @param session WebSocket session
 * @param UID     ID of call from web API
 * @param params  Params of call from web API
 */
public static void processPrintRequest(Session session, String UID, JSONObject params) throws JSONException {
    Format format = getPrintFormat(params.getJSONArray("data"));
    PrintProcessor processor = PrintingUtilities.getPrintProcessor(format);
    log.debug("Using {} to print", processor.getClass().getName());
    try {
        PrintOutput output = new PrintOutput(params.optJSONObject("printer"));
        PrintOptions options = new PrintOptions(params.optJSONObject("options"), output, format);
        processor.parseData(params.getJSONArray("data"), options);
        processor.print(output, options);
        log.info("Printing complete");
        PrintSocketClient.sendResult(session, UID, null);
    } catch (PrinterAbortException e) {
        log.warn("Printing cancelled");
        PrintSocketClient.sendError(session, UID, "Printing cancelled");
    } catch (Exception e) {
        log.error("Failed to print", e);
        PrintSocketClient.sendError(session, UID, e);
    } finally {
        PrintingUtilities.releasePrintProcessor(processor);
    }
}
Also used : PrinterAbortException(java.awt.print.PrinterAbortException) PrintProcessor(qz.printer.action.PrintProcessor) PrintOptions(qz.printer.PrintOptions) PrintOutput(qz.printer.PrintOutput) PrinterAbortException(java.awt.print.PrinterAbortException) JSONException(org.codehaus.jettison.json.JSONException)

Aggregations

PrinterAbortException (java.awt.print.PrinterAbortException)1 JSONException (org.codehaus.jettison.json.JSONException)1 PrintOptions (qz.printer.PrintOptions)1 PrintOutput (qz.printer.PrintOutput)1 PrintProcessor (qz.printer.action.PrintProcessor)1