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

How to print PDF in landscape #2

Open
rvarkelen opened this issue Feb 6, 2018 · 5 comments
Open

How to print PDF in landscape #2

rvarkelen opened this issue Feb 6, 2018 · 5 comments

Comments

@rvarkelen
Copy link

Hi,
Thanks for your package, it worked out of the box without too much issues! 👍

I'm trying to print a PDF in landscape to a Zebra printer.
I've tried to add an attribute landscape = true and orientation-requested = 4 but it fails.

Guzzle exception says: Bad Request

Cups error log shows: IPP read error: IPP enum value not 4 bytes

If I don't supply the attribute the label is printed but in portrait. I've also tried to use the 0x04 syntax but it returns the same error.

Any pointers?

Ubuntu 14.04
Cups 1.5.3
PHP 5.6.33 (Yeah I know, I know)

My code:

<?php
include '../../vendor/autoload.php';

use Smalot\Cups\Builder\Builder;
use Smalot\Cups\Manager\JobManager;
use Smalot\Cups\Manager\PrinterManager;
use Smalot\Cups\Model\Job;
use Smalot\Cups\Transport\Client;
use Smalot\Cups\Transport\ResponseParser;

$client = new Client();
$builder = new Builder();
$responseParser = new ResponseParser();

$printerManager = new PrinterManager($builder, $client, $responseParser);
$printer = $printerManager->findByUri('ipp://printserver:631/printers/GK420T');
$jobManager = new JobManager($builder, $client, $responseParser);

$job = new Job();
$job->setName('job create file');
$job->setUsername('demo');
$job->setCopies(1);
$job->setPageRanges(1);
$job->addFile('label_5a79e4c0ae949');
$job->addAttribute('orientation-requested', 4);
$result = $jobManager->send($printer, $job);
@slawkens
Copy link

slawkens commented Jun 6, 2018

Hello,

Did you manage to fix that issue?

Having the same issue here.

macOs 10.13.4
Cups 2.2.5
PHP 7.1.17

Tried all possible options:

$job->addAttribute('orientation-requested', 'landscape');
$job->addAttribute('orientation-requested', 4);
$job->addAttribute('orientation-requested', '4');

@rvarkelen
Copy link
Author

@slawkens I did not, unfortunately. I managed to get the PDF in landscape by using a external library (CzProject/PdfRotate), store it as a PNG with Imagick and use Zebra/Zpl/Image and Zebra/Zpl/Builder to output ZPL directly to the printer using fsockopen

@slawkens
Copy link

slawkens commented Jun 6, 2018

Thanks for your valuable input.

But, I wasn't satisfied with that workaround, requiring me to invest more time to modify my existing code, so I investigated more time into fixing this issue.

So, after trying many workarounds, I finally ended changing cups LogLevel to debug and watching the valuable logs file..
In /etc/cups/cupsd.conf

LogLevel debug

Then I checked generated log. It gave me valueable information about attribute that was not valid.
The message stated:

E [06/Jun/2018:14:59:18 +0200] [Client 7] IPP read error: IPP-Value „enum“ ist not 4 Bytes.

It indicated that value should have 4 bytes.

Ok, so let's try to modify our code to provide 4 bytes value as parameter :)

I've read how to convert php int to be 4-bytes here: https://stackoverflow.com/questions/26184947/convert-int-into-4-byte-string-in-php

$value = pack('N', 4);
$job->addAttribute('orientation-requested', $value);

Where 4 is our value for landscape.

That was the trick and it did the job!
The job was succesfully sent and printed by my printer :)

Hope it helps someone.

@rvarkelen
Copy link
Author

Thanks for the feedback 👍

@jimwins
Copy link

jimwins commented Dec 24, 2018

There's no real handling of enum values in the Smalot\Cups\Builder class, it just passes the value straight through (see the todo note on line 197 of src/Builder/Builder.php).

This patch will encode and pass through numeric values and throw exceptions on non-numeric ones.

A more complete implementation would require pulling out the various possible enum values from RFC 8011 and having resolving those.

jimwins added a commit to jimwins/cups-ipp that referenced this issue Dec 30, 2018
This partially fixes smalot#2, but a complete fix will
require handling the non-numeric values for enum fields. A table
of those could be pulled from RFC 8011.
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

3 participants