diff --git a/src/Mike42/Escpos/PrintConnectors/CupsPrintConnector.php b/src/Mike42/Escpos/PrintConnectors/CupsPrintConnector.php index 3ef25c8..f28e7d7 100644 --- a/src/Mike42/Escpos/PrintConnectors/CupsPrintConnector.php +++ b/src/Mike42/Escpos/PrintConnectors/CupsPrintConnector.php @@ -37,6 +37,20 @@ class CupsPrintConnector implements PrintConnector * The name of the target printer. */ private $printerName; + + /** + * + * @var int $jobNumber + * The job dispatch number + */ + private $jobNumber; + + /** + * + * @var int amountPages + * The amount of pages that CUPS reported to print + */ + private $amountPages; /** * Construct new CUPS print connector. @@ -91,13 +105,47 @@ public function finalize() escapeshellarg($tmpfname) ); try { - $this->getCmdOutput($cmd); + $response = $this->getCmdOutput($cmd); + $exploded = explode(" ", $response); + + // Set default data in case the checks fail, and make them obvioulsy incorrect + $this->jobNumber = -1; + $this->amountPages = -1; + + if (count($exploded) > 3) { + $jobName = explode("-", $exploded[3]); + $this->jobNumber = intval($jobName[count($jobName) - 1]); + } + + if (count($exploded) > 4) { + $this->amountPages = intval(substr($exploded[4], 1)); + } } catch (Exception $e) { unlink($tmpfname); throw $e; } unlink($tmpfname); } + + /** + * Retrieve the job number + * + * @return int Assigned job number, or null if the job has not yet been finalized. + */ + public function getJobNumber() + { + return $this->jobNumber; + } + + /** + * Retrieve the amount of files printed + * + * @return in The amount of files CUPS reported to print, or null if the job has not yet been finalized. + */ + public function getAmountPages() + { + return $this->amountPages; + } /** * Run a command and throw an exception if it fails, or return the output if it works. diff --git a/src/Mike42/Escpos/Printer.php b/src/Mike42/Escpos/Printer.php index 05c8a6f..68716be 100644 --- a/src/Mike42/Escpos/Printer.php +++ b/src/Mike42/Escpos/Printer.php @@ -1025,6 +1025,34 @@ public function textRaw(string $str = "") { $this -> buffer -> writeTextRaw((string)$str); } + + /** + * Returns job number assigned, only available if CupsPrintConnector has been used + * + * @return int Assigned job number, or null if the job has not yet been finalized or the printconnector does not support this function + */ + public function getJobNumber() + { + if (! $this -> connector instanceof \Mike42\Escpos\PrintConnectors\CupsPrintConnector) { + return null; + } + + return $this -> connector -> getJobNumber(); + } + + /** + * Returns amount of pages printed, only available if CupsPrintConnector has been used + * + * @return int Amount of pages printed, or null if the job has not yet been finalized or the printconnector does not support this function + */ + public function getAmountPages() + { + if (! $this -> connector instanceof \Mike42\Escpos\PrintConnectors\CupsPrintConnector) { + return null; + } + + return $this -> connector -> getAmountPages(); + } /** * Wrapper for GS ( k, to calculate and send correct data length.