qzind / qz-print

Archive for legacy qz-print versions (1.8, 1.9). See https://github.com/qzind/tray for modern versions.
Other
141 stars 101 forks source link

Printing raw images #178

Closed noramtkane closed 8 years ago

noramtkane commented 8 years ago

I am trying to raw print an image with qz-tray and I am running into an issue in which is tells me that it is unable to parse the base64 data as a raw command. The qz-tray log shows "Caused by: java.io.IOException: Bad Base64 input character '58' in array position 4"

I believe I can see what the issue is looking at the qz-tray 2.0 source.

In utils/ByteUtilities.java the isBase64Image function looks for a string that starts with "data:image/". However in printer/action/PrintRaw.java the same entire string is treated as base64 data in getImageWrapper.

You can see my example code here: https://jsfiddle.net/ckt6t26z/21/

tresf commented 8 years ago

We need to document this in our wiki. The old "data:image/" syntax is no longer valid, despite the lingering code. We'll cllean that up. Our API does better to explain how to do base64 images, but our wiki doesn't have any good examples yet, so we'll provide a working example today.

Until then, here's our API. Take a look at the data object and it will provide insight as to how base64 images are provided. https://qz.io/api/qz#.print

noramtkane commented 8 years ago

We are not using the 1.9 appendImage, if you take a look at the jsfiddle link I provided we are using the 2.0 API. I think the issue is the way that qz-tray determines if the image is a URL or base64 string is to check if it starts with "data:image/" if it does, it tries to decode the entire string without removing this, thus the error since ':' is not a base64 character. Look at the function that starts at line 119 in PrintRaw.java.

tresf commented 8 years ago

We are not using the 1.9 appendImage, if you take a look at the jsfiddle link I provided we are using the 2.0 API.

The 2.0 API is what was linked.

I think the issue is the way that qz-tray determines if the image is a URL or base64 string is to check if it starts with "data:image/" if it does, it tries to decode the entire string without removing this, thus the error since ':' is not a base64 character. Look at the function that starts at line 119 in PrintRaw.java.

This is actually a bug/gap in 2.0. We had switched the 2.0 branch away from using data:image/ but we left our raw API in the dust as it was never was expanded to allow this. We'll have this patched for our stable 2.0 release. We'll link an RC3 installer once we have this patched. Much appreciated.

noramtkane commented 8 years ago

So 2.0 will not be able to use a base64 data URI? It can be useful for using things like fabric.js to make labels.

tresf commented 8 years ago

So 2.0 will not be able to use a base64 data URI? It can be useful for using things like fabric.js to make labels.

No, not directly, but if you have the base64 data URI, you'll be able to do dataURI.split(',')[1]; to grab the stand-alone base64 value.

noramtkane commented 8 years ago

But that would require converting to bitmap in javascript for the printer, the way you had it does the conversion for you.

tresf commented 8 years ago

But that would require converting to bitmap in javascript for the printer, the way you had it does the conversion for you.

Base64 is supported for Pixel printing and will be supported for raw printing. The URI format has/will be dropped, but the image data is already in the URI string, so appending it will be a matter of splicing. Can you explain in further detail what your concern is?

tresf commented 8 years ago

Perhaps I was not clear, the ESCP/ZPL/etc conversion will still happen by our library.

noramtkane commented 8 years ago

So I can still provide the base64 data from a PNG or JPEG data URI to the library and it will convert it to the ZPL image format?

akberenz commented 8 years ago

Per b40dffd03d8a6ec344960647a31ac53504937b40, the data:image tags are no longer checked for because they shouldn't be provided.

noramtkane commented 8 years ago

Ah okay, I can see what you were saying from the commit. Sorry I got confused. Thanks!

tresf commented 8 years ago

This is available in RC3, available from our downloads page. https://qz.io/downloads