How to print Logo stored in Epson Printer using JavaPOS - epson

Want to know, how to print Logo stored in Epson Printer (TM-T88V) using JavaPOS, I used Epson Utility to store logo image in printer. I am using JavaPOS, POS is able to print receipt. I want to print logo on top but no luck. I tried to make some changes in Java file.
Any help will be great. Do i need specific code to add or i need to make change in jpos.xml.
Thanks

When you need to print pre-loaded logos you have to use directIO method with PTR_DI_PRINT_FLASH_BITMAP2 const.
Example (32 32 pre-loaded logo keycode):
String myobject = Integer.toString(POSPrinterConst.PTR_BM_CENTER);
int[] data = new int[]{0};
data[0] += 32; // LSB
data[0] += 32 << 16; // MSB
ptr.directIO(EpsonPOSPrinterConst.PTR_DI_PRINT_FLASH_BITMAP2, data, myobject);

For an image stored into NVRAM:
// This will print the image stored in position 2
ptr.directIO(EpsonPOSPrinterConst.PTR_DI_PRINT_FLASH_BITMAP, new int[]{2}, Integer.valueOf(POSPrinterConst.PTR_BM_CENTER).toString());
Where
Alternatively it is possible to load images when you are runing the program
To register a bitMap you can do:
POSPrinterControl114 ptr = (POSPrinterControl114)new POSPrinter();
ptr.setBitmap(1, POSPrinterConst.PTR_S_RECEIPT, "/path/to/file.bmp", ptr.getRecLineWidth() / 2), POSPrinterConst.PTR_BM_CENTER);
and when you want to print it:
ptr.printNormal(POSPrinterConst.PTR_S_RECEIPT, "\u001b|1B");
If you wantsetBitmap store images in NVRAM you must change property "UsedNVRAM" in your TM-T88V.xml file
<prop name="UsedNVRAM" type="String" value="1"/>
Or mark the checkbox on SetupPos app.
One problem is that this methods can't be mixed, for example, if you store images to NVRAM with setBitmap, you will not be able to print anything with directIO method
Anyway, I recommend to take a look into documentation folder when you download JavaPOS ADK, 1.14.18

You need to use something similar to the below:
ptr.printBitmap(POSPrinterConst.PTR_S_RECEIPT,YOUR_LOGO_PATH, POSPrinterConst.PTR_BM_ASIS, POSPrinterConst.PTR_BM_CENTER);
Does it work?

Related

How to save as PDF while printing a document on actual printer

I am trying to find a generalized solution on how to save the document as PDF while giving print on my actual printer on Windows 7/10 OS.
Scenario: Whatever I am printing whether an image or a file or from the third party app like POS or Screen Print (like user press pint button on the third party application or press CTRL+P if the third party app supported this hot key), i need to save the document as PDF which this document is reaching to the actual printer which is printing the hard copies. I wanted to generalized to support all kinds of printers be it dot matrix or laser or thermal etc...
Solution which I have tried out:
Virtual Printer which will print pdf and then route the pdf to the actual printer. But few printers doesn't support PDF like Thermal printer do not support PDF, moreover for this i need to take care of the paper settings and page settings.
I have tried Virtual Printers like Win2PDF / ClawPDF
I have looked into the Windows Printing architecture, and tried saving spool file and listening the printing event and routing the spool file to virtual printer to create pdf. This works partially as some of the printer drivers emits the RAW Spool file.
PCL & Postscript can be fine to convert to PDF.
Using Print processor like PrintMulti but the same issue like the 2nd one.
I have tried to look into the even if I can get some kind of input file from which Windows Printing creating the Spool file, but I am unable to get that.
I tried Printer Pooling but that is like a load sharing kind of things.
Could anyone help me on this. I am unable to find any solution over google as well so posting it here. It looks a normal thing to achieve but even after two weeks i am unable to find any solution for this. Is this something difficult to achieve the generalized solution?
Consider an approach using something like the ePrint Virtual Printer which works by capturing the Windows EMF file from the print job and converting it to PDF while also being able to still send the EMF to the physical printer and print it. The application itself allows for the creation of Print Tasks in a Virtual Printer, which can be configured to save to PDF and batch print to other printers.
On the other hand, ePrint is based on the LEADTOOLS Virtual Printer SDK, which could be useful for you to look into if you are looking to code your own approach.
For example, the code for an event that is hooked to a virtual printer to save the captured EMF as PDF:
// Write the EMF as file to disk as PDF.
static void VirtualPrinter_EmfEvent( object sender, EmfEventArgs e )
{
string pdfPath = Path.Combine(
#"c:\Output\PDF\",
Path.GetFileNameWithoutExtension( Path.GetRandomFileName() )
) + ".pdf";
Directory.CreateDirectory( Path.GetDirectoryName( pdfPath ) );
// Create an instance of the LEADTOOLS DocumentWriter
DocumentWriter docWriter = new DocumentWriter();
docWriter.BeginDocument( pdfPath, DocumentFormat.Pdf );
DocumentEmfPage page = new DocumentEmfPage() {
EmfHandle = new Metafile( e.Stream ) )
.GetHenhmetafile()
};
docWriter.AddPage( page );
docWriter.EndDocument();
}
If you are interested in more details, you can check out this article here.

How to print a logo on labels using a Zebra printer and sending ZPL instructions to it

I would like send ZPL instructions to a Zebra printer (GK420t for now).
I'm printing 50mm x 20mm labels.
I would like a logo (small ~ 5mm x 5mm image) to be printed on the upper left corner of the label.
I would like to know the steps I should follow to do this.
I have been reading and trying a few things from the ZPL manual but I don't really understand how it works and couldn't find a working example.
It looks like I have to "load" the image into the printer first (in a so-called "storage area"/DRAM?) and then print it.
The .GRF file extension is mentioned many times in the manual.
I couldn't find the tool to convert a .PNG or .BMP image into a .GRF file.
I read that a .GRF file is an ASCII HEX representation of a graphic image... but it didn't help me do the work.
I could print the logo on the labels using the "Zebra Setup Utilities", by "Downloading Fonts and Graphics", choosing any available .MMF file, adding a .BMP picture, downloading it [to the printer] and printing a test page.
But until now, I couldn't do it using ZPL instructions.
I am also wondering what are the best dimensions I should use given the fact that I need a small image ~5mm x 5mm to be printed on the labels.
The image I printed is a 40px x 40px image.
Also, if I have to make a .GRF file from an original image what should be the type of this file (.BMP, .PNG, .JPG)?
Can you advise me how to proceed?
It sounds like you have some existing ZPL code, and all you want to do is add an image to it.
If that's the case, the easiest solution is probably to go to the Labelary online ZPL viewer, paste your ZPL into the viewer, click "Add image", and upload the image that you want to add to the ZPL.
This should modify your ZPL by adding the image ZPL commands that you need, and you can then tweak the position, etc.
Here is another option: I created my own image to .GRF converter in python. Feel free to use it.
from PIL import Image, ImageOps
import re
import itertools
import numpy as np
# Use: https://www.geeksforgeeks.org/round-to-next-greater-multiple-of-8/
def RoundUp(x, multiple_of = 8):
return ((x + 7) & (-1 * multiple_of))
def image2grf(filePath, width = None, height = None, rotate = None):
image = Image.open(filePath).convert(mode = "1")
#Resize image to desired size
if (width != None):
size = (width, height or width)
if (isinstance(size[0], float)):
size = (int(size[0] * image.width), int(size[1] * image.height))
#Size must be a multiple of 8
size = (RoundUp(size[0]), RoundUp(size[1]))
# image.thumbnail(size, Image.ANTIALIAS)
image = image.resize(size)
if (rotate != None):
image = image.rotate(rotate, expand = True)
image_asArray = np.asarray(np.asarray(image, dtype = 'int'), dtype = 'str').tolist()
bytesPerRow = len(image_asArray[0])
nibblesPerRow = bytesPerRow // 4
totalBytes = nibblesPerRow * len(image_asArray)
#Convert image to hex string
hexString = "".join(
format(int("".join(row[i*4:i*4 + 4]), 2) ^ 0xF, "x")
for row in image_asArray
for i in range(nibblesPerRow)
)
#Compose data
data = "~DGimage," + str(totalBytes // 2) + "," + str(nibblesPerRow // 2) + "," + hexString
#Save image
fileHandle = open(r"labelPicture.grf", "w")
fileHandle.write(data)
fileHandle.close()
if __name__ == '__main__':
# image2grf(r"warning.bmp")
image2grf(r"pallet_label_icons.png", rotate = 90)
Edit: I updated the code above to use my new conversion method, which produces better resolution GRF files
Just install ZebraDesigner, create a blank label, insert a image object to the template and add the required logo image.
Print to File this label (a *.prn file) and open the recently created file with Notepad++ (MS Notepad will ruin the data if opened and saved with). Find a huge string of seemingly random characters, and there is your image's data. Careful not to lose any of those characters, including the control ones, as the whole string is a textual representation of your image (as it would be if it were base64).
Tip0: Always have your ZPLII Programmer's Guide at hand, you'll need/want to check if ZebraDesigner sent the image to memory or directly to the printer buffer.
Tip1: Before adding the logo to the label and get the text, prepare the image making it greyscale (remember to check the printer's dithering configuration!) or, in my case, plain black and white (best result IMHO). The image can be colored, the ZebraDesigner will make it work for the printer converting the image to greyscale before conversion to commands and text.
I created a PHP script to convert PNG images to .GRF similar to Josh Mayberry's image2grf.py:
https://gist.github.com/thomascube/9651d6fa916124a9c52cb0d4262f2c3f
It uses PHP's GD image function and therefore can work with all the file formats GD can open. With small modifications, the Imagick extension could be used but performance seems to be better with GD.
Try codeproject's sharpzebra project. The test program that is part of project prints a graphic and I know this works at least it did on a ZM400
go to Object ==> Picture and your curser will change to something else.. when it changed go and click on the working area and a dialog box iwll apear... so on there select the image so you can see the image whant you wanna print on the printer i am using GT800 so for me i did like that hope this will helps you
Use ZebraNet Bridge Enterprise Software to convert BMP to GRF file format
I had to figure this out again today. In the ZPL code, you can output the graphic bytes for every single label (which means a lot of additional data when you're printing a few thousand labels), or you can define the image first and then refer to it.
I used an online ZPL viewer to save on the number of labels printed when testing. I used:
http://staging.advanced-technology-group.com/
and here is another that does the same:
http://labelary.com/viewer.html
These (currently) have an 'add image' function. This transfers a png to the GRF format that ZPL works with (see the other answers if you need to generate these bytes yourself).
Outputting the bytes for every label
Using the "Add image" function generates a command and the graphic bytes, which looks like:
^FO50,50^GFA,11118,11118,17,,<lots of data>
You can adjust the FO as that tells the printer where to position the graphic.
That should be fine for shorter runs / smaller pictures / you're in a hurry.
Downloading the image once and then referring
This is what I had to do, so I needed to rearrange the bytes a bit (nice pun?).
THe ^GF command stands for Graphic Field: ^GFa,b,c,d,data where
a: A|B (A, non-binary, B = binary)
b: number of bytes transmitted
c: number of bytes comprising the graphic format
d: number of bytes per row
and what I needed to do is to reformat this as ~DGR:000.GRF,11118,17,, so that I could refer to it with ^XGR:000.GRF,1,1. After the print run, I'd need to delete the graphic from memory again with: ^ID000.GRF
The properties for ~DGd:o.x,t,w,data mean
d: memory destination - R for RAM
o: image name (1-8 alphanumeric chars)
x: filename extension, always GRF
t: number of bytes in the graphic
w: number of bytes per row
So I turned:
^FO50,50^GFA,11118,11118,17,,<data>
into:
~DGR:000.GRF,11118,17,,<data>
This definition goes before the label-definition, so:
~DGR:000.GRF,11118,17,,<data>
^XA (start of label)
...
^FT360,700^XGR:000.GRF,1,1^FS <-- this outputs the graphic
...
^XZ (end of label)
^ID000.GRF

In ActionScript3, how to Embed a list of Bitmaps (or BitmapData) in bulk?

I'm looking to create a Vector of BitmapData that can be used in animating a Bitmap. However, what's the preferred method for embedding large amounts of images? Or am I going about this task the wrong way entirely?
I know how to embed images like so:
[Embed(source="/assets/01.gif"]
public static var BYTES_01:Class;
For instance, but is there an easier way to just load a list of bitmaps (01-99?)
Thanks.
Since every tag is there to represent a single embedded file you cannot specify a range within a tag.
There are however alternatives:
If you use AIR with Flash Professional or Flash Builder you can embed a file or a whole folder and later access these files on-run time
If you use Flash Professional you can use the library and make the export settings to export images as bitmaps or cache them as bitmaps.
You can attach an external library to your project if you don't want to develop the project in FB or Flash Pro.
You can always make a script to write the embed tags for you :) You can even specify the file-names for readability. Let me give you an example:
for ( var i:int = 0; i < MAX_NUMBER; i++) {
var string:String = '[Embed(source="/assets/'+ fileName + i.toString() +'.gif"]\n';
string += 'public static var ' + CLASS_NAME + i.toString() + ':Class;\n\n'
trace(string);
}
Then just run the code in a new FLA file just in the frame and copy the output. Sure it's not ideal, but it will sure save you the time to write it by hand.
Hope that helps!

How to see image data using opencv in visual studio?

I wrote an OPENCV project in VS2010 and the results were not the ones as I expected so I ran the debugger to see where is the problem. When I wanted to see the data inside the image loaded I didn't know how to do it so if I want to see the data inside my images what should I do?
It is pretty simple in matlab for seeing different channel of an image i.e.
a=imread('test.jpg');
p1 = a(:,:,1)
p2 = b(:,:,2)
.
.
In opencv I wrote the same thing but I don't know how to see all the element at once just like Matlab.
a= imread("test.jpg")
split(a,planes);
vector<Mat> T1;
T1 = planes[0];
// How can I see the data inside T1 when debugging the code ?
I think this is what you are looking for - it's a great Visual Studio add-on
https://bitbucket.org/sergiu/opencv-visualizers
Just download the installer, make sure VS is closed, run it, re-open VS and voila! Now, when you point to an OpenCV data structure, all kinds of nice info is showed.
Limitations: I saw some problems with multichannel images (it only shows the first channel) and it also has trouble displaying large matrices. If you want to see raw data in a big matrix, you can use the old good VS trick with debug variables: Stop at a breakpoint, go to Watch tab, and write there
((float*)myMat.data) ,10
Where float is the matrix type, myMat is your matrix, and 10 is the number of values you want to print. It will display the first 10 values at the memory location of myMat.data. If you do not correctly choose the data type, you'll see garbage. In my example, myMat is of type cv::Mat.
And never forget the power of visualizers:
imshow("Image", myMat);
If your data fits into an image. You can use the contrib module's colormap to enhance your visualizers.
I can't actually believe that nobody suggested Image Watch yet. It's the most amazing add-in ever. It shows you a view with all your Mat variables (images (gray and color), matrices) while debugging, there's useful stuff like zooming or contrast-stretching and you can even apply more complex functions directly in the plugin in real-time. It makes debugging of any kind of image operations a breeze and it's immensely helpful if you do calculations and linear algebra stuff with your cv::Mat matrices.
I recommend to use a NativeViewer extension. It actually displays the content of an image in a preview window, not only the properly formatted info.
If you don't want to use a plug-in or extension to Visual Studio, you can access the elements one by one in the debugging watch tab by typing this:
T1.data[T1.step.buf[0]*i + T1.step.buf[1]*j];
where i is the row you want to look at and j is the column.
after downloading imagewatch use the command in watch window
(imagesLoc._Myfirst)[0]
index of image in the vector
You can use the immediate window and the extenshion method like this one
/// <summary>
/// Displays image
/// </summary>
public static void Display (this Mat m, Rect rect = default, string windowName = "")
{
if (string.IsNullOrEmpty(windowName))
{
windowName = m.ToString();
}
var img = rect == default ? m : m.Crop(rect);
double coef = Math.Min(1600d / img.Width, 800d / img.Height);
Cv2.ImShow(windowName, img.Resize(new Size(coef * img.Width, (coef * img.Height) > 1 ? coef * img.Height : 1)));
Cv2.WaitKey();
}
Then you stop at a breakpoint and call yourImage.Display() in the immediate window.
If you can use CLion you can utilize the OpenCV Image Viewer plugin, which displays matrices while debugging just on click.
https://plugins.jetbrains.com/plugin/14371-opencv-image-viewer
Disclaimer: I'm an author of this plugin

Changing bit format on a Windows mobile device through direct draw APIs

I am working on a Windows Mobile 6.5 device and want to copy an image from one application (drawn using GDI) to another application (using direct draw). Currently I am doing bit conversion for this since the direct draw supports only 16-bit whereas the GDI image is written using 24-bit. I am wondering if we can change the direct draw format so that I can avoid this conversion.
DDPIXELFORMAT format;
m_pPrimarySurface->GetPixelFormat (&format);
if (format.dwRGBBitCount == 16)
{
format.dwRGBBitCount = 32;
format.dwRBitMask = 0x00FF0000;
format.dwGBitMask = 0x0000FF00;
format.dwBBitMask = 0x000000FF;
}
Is it possible to change the bit format by directly setting it or through any direct draw APIs like SetPixelFormat etc.? Or is this some hardware setting and cant be changed?
The API SetDisplayMode() says that "Windows CE does not support display mode changes".
msdn.microsoft.com/en-us/library/ms893936.aspx

Resources