How to print in table-like structure on receipt ESC/POS - java

I'm trying to print a receipt using android and Bluetooth printer. I've managed to print text normally and using ESC/POS command for some of the texts. However I can't figure out how to print a table-like structure like:
I've tried to use reverse-feed but the printer doesn't seems to support it (I tried with a few commands but didn't work). Currently the only way I can think of is to calculate the length of each number and add space between them to look like a table. Is there a way to do this by using ESC/ POS command?

Related

Adding control data to plain text print job

Sorry for the long winded question, I've spent a few days trying to figure this out and have so far found dozens of ways not to solve my problem.
I'm currently trying to use a Datamax O'Neill E Class Mark 3 printer to print some labels. The java application that generates the label data cannot be easily modified, and simply outputs plain text via a built in "print" function (output example below)
Unit name [LF]
Unit description [LF]
Quantity
When I print to a Ricoh printer it works (using CR+LF replacement in the Ricoh driver). However when I print to the label printer it does not. I've been advised that the label printer requires "control codes" and "encoded data" to be able to print.
I've been able to log the .prn files from the printer and when sending the exact same data from Notepad to he printer, the .prn file is much larger and appears to be "encoded" containing control codes.
This is entirely inside a windows environment using a networked printer (tried USB as well). I basically need something for my Java application to print to, that will add the necessary "encoding" to the data and then pass it along to the Datamax printer. Any ideas?
I'll try and post some samples tomorrow when I'm in the office as I'm currently typing this on mobile.
What I ended up doing was using the printers logging feature to log all jobs to C:\printlogs\ and have a batch file that loops every few seconds to run notepad /P on each file in the folder and then clean them all up.
I know it's a messy workaround, but it works.
When you print text from something like Notepad, that text gets sent to a print driver that converts it into the format the printer understands. You can't generally add control codes to the text in Notepad and have it work because it won't be seen as anything other than plain text to be printed.
The programmer's manual for that printer can be found here. That gives you everything you need to know to print labels on that printer. But in order to send those commands to the printer, you can't just paste them into Notepad. You have to write them directly to the printer, bypassing the print driver. For that you're going to need to use the WritePrinter function. The sequence of steps for printing goes like this:
To begin a print job, call StartDocPrinter.
To begin each page, call StartPagePrinter.
To write data to a page, call WritePrinter.
To end each page, call EndPagePrinter.
Repeat 2, 3, and 4 for as many pages as necessary.
To end the print job, call EndDocPrinter.
The MSDN entry for WritePrinter includes a link to example code (in C).

how to print values in already designed A4 paper in Java?

I'm creating Web App using Java,And one of the tasks is to print a report to the customer.The problem is that the paper design is already made and putted in the actual printer and I must only fill the blank fields.The questions are :
1) how can I print the values exactly in the fields ?
2) Is there a way to simulate this process without having physical printer, like using virtual printer and upload the default page to it ?
I attached part of the paper that will be in the printer and I should fill the blank fields with data comes from JSF page.
I solved the problem like yours in the past. My company has a pre-designed printed invoice. My task is to put the data into the blanks in place. In my experience, you should:
Scan the paper into an image with the same size as the physical version.
Measure the distance from a blank to another.
Specify the location of the blanks to output the data based on your measurement.
You can use the digitalized version as the background of the output page and test on it.
Try to put the first blank in place.
Test and adjust your code.
Hope it helps.
If the things that are there in the page only in the soft copy you can do one thing. Design a A4 exactly the same way you have on the printed page. Then write down variables in the places where you would like to fill up from your java program. That docx file will act as the template. After that, replace those texts with the actual values from the Java program in that template. All these can be done with docx4j api.
A code block like this will be useful :
if (textElement.getValue().contains(placeholder)) {
String temp = textElement.getValue();
temp = temp.replace(placeholder, name);
textElement.setValue(temp);
return;
}
This is how we do it our project. If you need more help, let me know.

Java Extending StreamPrintService -- how do I implement a 'Print to Postscript File' type of 'printer'?

I am having a hard time trying to something simple in Java, but I have been beating my head against a wall for the better part of a day.
I am implementing a program that has a print feature. What I want to print is HTML text in a JEditorPane and I know I can use the print() method to print it to a printer, but I want to also print it to a file (PostScript or PDF, I don't really care which). I know that there exists somewhere in the depths of the JRE is code to convert the rendered contents of the JEditorPane to PostScript, since the printers I am dealing with are PostScript printers and that that is the standard output format for UNIX/Linux printers. Is there a way to leverage that to print to a file, without having to completely re-invent the wheel? I have been running web searches and randomly hacking code for the past couple of days with absolutely no meaningful progress.
As far as I can tell this is just not easily doable with Java. Instead, I found a package that implements 'exporting' the contents of the GUI (a JTextPane) to a PDF file, so I just added an additional toolbar button & menu item to 'Export to PDF'.

Silently print in the web page

All, I am trying to look for some solution to print the data in the webpage silently,
the printer type is Datamax e-4205A Label Printer, But so far I am stuck with it , Any Idea?
Any way , Is it possible to program an Activex control based on the printer API? thanks.

Building Web Based SQL like client

We are storing our data in an internal key-value store in few different data formats, To view or update data in the store I have built a command line tool which accepts a commands in a custom query language (similar to Object Query Language) parses, interprets and displays it on the console.
I am thinking of building a web based GUI for this. Since I have limited experience with this, wanted to know what would be the easiest way to do it (in java).
Currently the UI just needs to have two elements a text area for accepting commands and a table for displaying the output. The output table should be simple enough to implement but I am stuck on the input element part, since the console application provides history of the commands by default but I am not sure what GUI element would be good for this. An alternative would be to have a big text box in which the user can type multiple commands and run any of them by simply highlighting and executing it like most standard gui sql clients do (
http://mywebsql.net/screenshots/?cat=Sql+Editors#/images/screens/02.Sql%20Editors/Multiple%20Editors.png)
I went through the Google Web Tool kit widget gallery ( https://developers.google.com/web-toolkit/doc/latest/RefWidgetGallery ) but none of them seem to fit my need.
Any suggestions on this would be very helpful.
Thanks
I don't think you'll find any component providing a history of previously executed commands for you. But nobody forbids you to implement your own solution.
Just provide a text field or text area to type a command, and display a list of previous commands next to the text field/area. When a previous command is clicked, replace the text of the text area by the text of the clicked command. And when a command is executed, add it to the history list.
Any web framework, from basic servlet/JSP to component-based framewoks, should allow you doing that.

Categories

Resources