× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Rick,

The way I did it in the past with a line printer (which I had to access from several computers) was to share the line printer on a Win2K print server and then open the UNC path to the printer as an output file stream from my Java code. I think you could also print to open LPTx: or COMx: on the local machine as if they were files too, but I've not tried that in a while.

If you want to get more sophisticated about it, you could try working with the parallel or serial port directly. This is something I've never tried personally, but if you want to give it a go then I'd suggest starting with http://www.rxtx.org/, which is a toolkit that allows this kind of stuff. Sun actually has an API for port access, but I don't think it's supported in Windows any more.

(In all of this I'm assuming that your Java code will be running on Windows based on your Swing comments in the initial post... please let me know if I'm wrong.)

t.

On 1-Feb-07, at 10:25 AM, Rick DuVall wrote:

Hi Tamas,
        Thanks For the response.  I have printed to these printers before
using rpg and understand the 'language' they talk fairly well.  What
classes/methods should I use to locate the printer in windows and send
strings of commands to it? This is all new to me in Java and sometimes the approach or terminology they use is so foreign to me that I can't even find
where to get started - it always looks simple after I get it to work
<smile>.

Regards,
Rick

-----Original Message-----
From: java400-l-bounces@xxxxxxxxxxxx
[mailto:java400-l-bounces@xxxxxxxxxxxx] On Behalf Of Tamas Perlaky
Sent: Thursday, February 01, 2007 8:43 AM
To: Java Programming on and around the iSeries / AS400
Subject: Re: Printing in Java

Hi Rick,

There are two different issues here: (1) printing from Java
and (2) printing to a thermal printer.

Printing from Java is relatively easy; the standard Java
libraries include reasonably good printing APIs for obtaining
a printer, creating pages, and using graphics primitives to
populate the pages with text and/or graphics.  This works
great when printing to today's typical output devices (laser
printers, etc.).  It doesn't work so well for printing to
line printers (dot matrix or whatever), and when I've had to
do that in the past I've gone a bit lower level and just sent
a text stream directly to the printer port, an approach which
has plenty of its own issues and for which someone else may
have a better solution.

With thermal printers (at least in the warehouse/shipping
environments that I've worked with them in) the challenge is
that each one has it's own printer control language to define
the label and send data to the printer.  It's really a lot
like printing to a line printer, except instead of printing
lines of text you're printing control instructions.  Some
thermal printers come with windows printer drivers that allow
you to treat them as a regular windows printer (and there are
third-party drivers available also) and while that would
allow you to use the normal Java printing APIs but it would
also mean that each label would be sent to the thermal
printer as a bitmap, which tends to be grossly inefficient
compared to sending raw control instructions.

If I had to do this, my approach would actually be to use a
label printing tool (my choice would be Seagull Scientific's
BarTender) to drive the actual label printing.  The way that
would work is you'd define the label layout using their GUI
interface, and then from your Java code you'd either create a
CSV data file or populate some DB2 tables which the label
design is tied to, and let BarTender worry about the details
of sending that to the printer.  You can get an
unlimited-user three-printer Enterprise license of BarTender
for under $800, which is I suspect is much less than the cost
of going it alone.  The main downside of this is that
BarTender is Windows only (but the printer can be connected
via the network).

Alternately you could just use the regular Java printing
system with a Windows driver, or you could hit the books and
learn the control language for your printer and control the
printer directly.  Many current thermal printers actually
have a direct network interface, so depending on the model
you might be able to avoid issues of having to send data
directly to a serial or parallel port.

Hope some of this rambling helps!

(Oh also, just in terms of general printing, there are lots
of libraries both free and commercial to help you do
printing/reporting from Java.  I haven't used one is several
years as I do all my reporting to PDF via iText, but if it
wasn't for the thermal printer requirement here I'd recommend
looking around for one of those, too.)

t.

On 1-Feb-07, at 9:07 AM, Rick DuVall wrote:

Hi Group,

    I have written several swing apps (desktop client ->
iSeries-i5-whatever), but have never used java to print anything.
I now
have a need to produce print-out on a little thermal
printer as part
of the new app I'm working on.  Can anybody point me in the right
direction?  What I've found so far seems a bit convoluted. ;)  Of
course much of java has struck me that way... <smile>

    I continue to dig, but pointers are always welcome.  Thanks in
advance!


--
This is the Java Programming on and around the iSeries / AS400 (JAVA400-L) mailing list
To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.