Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad Request (HTTP 400) #7

Closed
c-scholz-acribit opened this issue Aug 13, 2018 · 3 comments
Closed

Bad Request (HTTP 400) #7

c-scholz-acribit opened this issue Aug 13, 2018 · 3 comments

Comments

@c-scholz-acribit
Copy link

c-scholz-acribit commented Aug 13, 2018

I am using the library inside a Laravel 5.6 application.

When I try to print a document I get an exception (HTTP-Statuscode 400 - "Bad Request").

$client = new Client('scholz', '123456');
$builder = new Builder();
$responseParser = new ResponseParser();

$printerManager = new PrinterManager($builder, $client, $responseParser);
$printer = $printerManager->findByUri('ipp://localhost:631/printers/inpas');

$jobManager = new JobManager($builder, $client, $responseParser);

$job = new Job();
$job->setName($printjob->title);
$job->setUsername('scholz');
$job->addFile('./storage/app/'.$printjob->file);
$job->addAttribute('media', $printjob->format);
$job->addAttribute('orientation-requested', $printjob->orientation);
$job->addAttribute('fit-to-page', true);
$job->setPageRanges($printjob->range);

$result = $jobManager->send($printer, $job);

Check a screenshot of the Exception here:
https://www2.pic-upload.de/img/35784064/Bildschirmfotovom2018-08-1316-47-35.png

Any ideas what I could try? The provided data in the $printjob Object is correct, too, because I fixed any errors with this by now. Also I added www-data user (Apache) to lp usergroup in Ubuntu.

I am just wondering how I'd maybe get around this 400 error and finally print a pdf...

@c-scholz-acribit
Copy link
Author

c-scholz-acribit commented Aug 15, 2018

Okay I came to the conclusion that actually some provided values were wrong or I called them wrongly. Here's what I found out or need help with @smalot

  • setCopies() can not be omitted and param cannot be null (should be mentioned somwhere imho)
  • setPageRanges() can not be omitted and param cannot be in the allowed format for lp printing "-n, n, n-m, n-" but only in format "n-m, n" (should also be mentioned somewhere)
  • I couldn't get the "orientation-requested" attribute to work, maybe I am confused but my printer returned this when I called $printer->getAttributes(); :
    "orientation-requested-supported" => [ 0=>"portrait", 1=>"landscape", 2=>"reverse-landscape", 3=>"reverse-portrait"] and I tried all combinations: " $job->addAttribute('orientation-requested', 'landscape'); , $job->addAttribute('orientation-requested', 1), $job->addAttribute('orientation-requested', 1)
    also with value 4 (like it's stated in the CUPS documentation for command line printing) and the setAttribute()-method, yet the request keeps returning a 400 HTTP error
    edit: after checking the other issues here, I found the solution provided - we need to change the provided value to a 4 Byte value with pack('N', $val)
  • how do I set options I find with lpoptions -d [printername] ? like "Collate", "ColorModel", "PageSize", "InputSource" etc.
    edit: I checked IPP implementation and chose to use "sheet-collate" & "multiple-document-handling", "print-color-mode", "media" and "media-source" for the aforementioned options

@c-scholz-acribit
Copy link
Author

Duplicate of #2

@chriskonnertz
Copy link

It might also be worth a note, that there is no straight way to print "all" pages of a document. setPageRanges() cannot be ommitted,so we have to specify a range. One solution is to use something like `setPageRanges('1-99')' - just set the max range value to a high value that you hopefully will never exceed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants