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).
Related
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?
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.
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'.
I've done a lot of internet searching to find some information to no avail.. Hopefully you can help me..
I want to be able to use a flat file, with normal content (i.e. full english sentences, paragraphs etc), extract each word and store each word individually, one word per row, in a SQL database (doesn't matter if there are spaces but characters such as apostrophes can be kept in)
I then want to have a HTML page with code to access this DB and output the text to the user one word at a time, essentially 'writing' the inputted files text word-by-word on the web page.
This is just a coding exercise but I am frustrated as I know the what but not the how.. I am not sure where to start. Please note some of these files can be quite big ~ 20,000 words so there may be a performance element to consider to any solution.
TL;DR: I want to extract individual words from a text file with normal everyday sentences into a SQL DB that I can retrieve from a HTML page.
Simple read & split exercise
with open(<filename>) as f:
dd = {}
for ln in f:
wds = ln.strip().split()
for word in wds:
dd[word] = 1 # need something for value
for wkey in dd:
<insert into db>
Well, before you start you should choose just one programming language. Since you seem like you are a beginner I would highly recommend Python over Java, but it depends on if you're required to use any particular language by an employer/professor/etc.
Also just to point out, this is also a very BIG task that you've chosen. I'll try to break it down into parts for you, but I recommend starting with just one of these parts before you move on, and make sure it works on your local machine before you try putting it on the web.
First you need to use something read in your file, preferably line by line. A method similar to FileReader/BufferedReader in Java or the open(), readlines() functions in Python will do these. I would also check out the tutorials online on file handling for whichever of these two languages you're going to use. The Python one is here. Practice this with a test file or a small section of your real file before you start working on your real input files.
When you start processing the lines from the file, I would recommend splitting them into individual words using a string split function on spaces or on any punctuation, such as ,.!?". This way you'll pull out the individual words from the each line in the file.
Next, you'll want to choose a database API for the appropriate programming language. I used PyMySQL but there is also MySQLDB for Python. In Java there is JDBC.
You'll need to then build your database on a server somewhere, preferably on the same server as your HTML page for ease of connection. You'll want to practice connecting to your database and adding sample rows before you start trying to process your real input files.
You can't have normal HTML access the database directly - you'll need to use a coding language like Python for that. I've never used Java for webpages, but with Python you'll simply output text and tell the server to display it as the webpage. This will do the trick:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import otherstuffhere
## Must have this header to tell browser how to handle this output
## and must be printed first
print ("Content-Type: text/html\n\n")
## Connect to database here
## Your code to display words from the database goes below here
print (myfield1)
Also remember that when you output your text, you'll need to add all the HTML tags to the normal text output. For example, when printing each word, you'll need to add <p> or <br> to end each line, because although the Python print() function will automatically add a line break, this doesn't translate to a line break in HTML. For example:
print ("My word list is: <br>")
for word in dbOutputList:
print (word)
print ("<br>")
After that the REAL fun/crying begins, but you should work on the above before you move on.
Hi I need to show the result in a memo instead using System.out.println, but isn't possible to put the stdout in a list for example and after display the contents of this list in swing memo because I need to display every line of the result in real time or when it is showed.
I'm think in something that works like an observer of System.out.println and when some data or information have been printed in the console I want to be able to capture it and display in a memo.
For a better comprehension, I execute some commands remotely in an unix server and retrieve the results of these commands in the stdout and compute some time and metrics with them, and definitely I need to do in this way to simulate the behavior of an remote application.
The solution could be a way to show every line or every item in the list in the memo in the exactly time that it is produced.
And the swing memo can deal with big strings, more than 500kb or more than 1MB?
Because the entire result printed in the sdtout in my ID is really huge.
Thx
See Message Console, for which the description states:
There may be times when you want to capture output from your program and display it for the user. This is generally done by creating a console. Using Swing it is not too difficult to create a simple console using a JTextArea or JTextPane. Our message console will be able to display output written to System.out and System.err. ..
Message Console Screenshot
The JTextPane form of Message Console in append mode.
(Screenshot obtained from the linked article at Rob Camick's 'Java Tips Weblog'.)
You can find what you are looking for here :
The webpage is in French, but still code, is quite clear and in java.
Basically, they use to threads to read from 2 PipedOutputStream. One of them is plugged on System.out, the second one is plugged on System.err. When something is available in one of the pipedOutputStream, they write it in the widget.