I want to print labels from my web application and to do that I am using this packages. (https://github.com/smalot/cups-ipp). Im using the example code provided by the package and when I send PDF file to print Im getting the following error:
Http\Client\Common\Exception\ClientErrorException(401) Unauthorized
When I look at my printers queue I see the status is aborted and the size of the file is 0KB. I am sure the file is found the right way because when I do some debugging I can see that the stream of the PDF is coming in right but in the request that is send I can't found it back. The request is as followed:
Request {#995 ▼
-method: "POST"
-requestTarget: null
-uri: Uri {#996 ▼
-scheme: ""
-userInfo: ""
-host: ""
-port: null
-path: "/"
-query: ""
-fragment: ""
}
-headers: array:1 [▼
"Content-Type" => array:1 [▼
0 => "application/ipp"
]
]
-headerNames: array:1 [▼
"content-type" => "Content-Type"
]
-protocol: "1.1"
-stream: Stream {#998 ▼
-stream: stream resource @14 ▼
wrapper_type: "PHP"
stream_type: "TEMP"
mode: "w+b"
unread_bytes: 0
seekable: true
uri: "php://temp"
options: []
}
-size: 140
-seekable: true
-readable: true
-writable: true
-uri: "php://temp"
-customMetadata: []
}
}
I don't know if its valuable but my application is build on laravel 5.6.
The code for executing the print job:
public function testPrinter() {
$client = new Client();
$builder = new Builder();
$responseParser = new ResponseParser();
$printerManager = new PrinterManager($builder, $client, $responseParser);
$printer = $printerManager->findByUri('ipp://localhost:631/printers/OKI_ES7131_D66B77');
$jobManager = new JobManager($builder, $client, $responseParser);
$job = new Job();
$job->setName('job create file');
$job->setUsername('kasper');
$job->setCopies(1);
$job->setPageRanges('1');
$job->addFile('/var/www/justproduce/public/helloworld.pdf', 'test');
$job->addAttribute('media', 'A4');
$job->addAttribute('fit-to-page', true);
$result = $jobManager->send($printer, $job);
}
Had to initialize a new client with credentials. Works now.