Skip to content

Commit

Permalink
Update how page range is set - #3
Browse files Browse the repository at this point in the history
  • Loading branch information
rawilk committed Sep 5, 2020
1 parent 710c865 commit f0d0a3f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Drivers/Cups/PrintTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,17 @@ public function range($start, $end = null): self
{
$range = $start;

if (! $end && ! Str::startsWith($range, [',', '-'])) {
$range = "{$range}-"; // print all pages starting from $start
if (! $end && Str::endsWith($range, '-')) {
// If an end page is not set, we will default the end to a really high number
// that hopefully won't ever be exceeded when printing. The reason we have to
// provide an end page is because the library we rely on for CUPS printing
// doesn't allow "printing of all pages", i.e. 1- syntax.
// see: https://github.com/smalot/cups-ipp/issues/7
$range .= '999';
} elseif ($end) {
$range = "{$start}-{$end}";
$range = Str::endsWith($range, '-')
? $range . $end
: "{$range}-{$end}";
}

$this->job->setPageRanges($range);
Expand Down Expand Up @@ -124,7 +131,8 @@ public function send(): PrintJob
}

if (! $this->job->getPageRanges()) {
$this->range(1);
// Print all pages if a page range is not specified.
$this->range('1-');
}

$success = $this->jobManager->send($this->printer, $this->job);
Expand Down

0 comments on commit f0d0a3f

Please sign in to comment.