language = \OC::$server->getL10N('printer'); $this->printer = $printer; } /** * @NoAdminRequired */ public function printfile(string $sourcefile, string $orientation): JSONResponse { $file = \OC\Files\Filesystem::getLocalFile($sourcefile); $success = [ 'response' => 'success', 'msg' => $this->language->t('Print succeeded!'), ]; $error = [ 'response' => 'error', 'msg' => $this->language->t('Print failed'), ]; if (!$this->printer->isValidOrirentation($orientation)) { return new JSONResponse($error); } try { $this->printer->print($file, $orientation); return new JSONResponse($success); } catch (ProcessFailedException $exception) { return new JSONResponse($error); } } }