Results 1 to 2 of 2
Thread: Sending text to printer
-
Sending text to printer
Example below sends the text to the printer for printing. Its a very simple way of doing things.
Java Code:import java.io.*; public class SimplePrinting { public static void main(String[] args) { try { FileWriter out = new FileWriter("lpt1"); out.write("Hello world"); out.write(0x0D); // CR out.close(); } catch (IOException e) { e.printStackTrace(); } } }
- 05-25-2009, 06:14 AM #2
Member
- Join Date
- Feb 2008
- Posts
- 8
- Rep Power
- 0
With JAVA, this writes to a file called "lpt1". Yes, this is extremely useful. Here's a simple method that takes a string and produces a physical piece of paper with words on it. Better yet it provides a dialog to which the user can select what printer and many (but usually not all) printer settings.
Java Code:PrintingTask.print("Hello World");Java Code:class PrintingTask extends SwingWorker<Object, Object> { private JTextArea text = new JTextArea(); public PrintingTask(String data) { text.setText(data); this.execute(); } public static void print(String data) { new PrintingTask(data); } protected Object doInBackground() { try { text.print(new MessageFormat(""), new MessageFormat(""), true, null, null, true); } catch (PrinterException ex) { //Opps... cant print. Insert error handling code here. } return null; } }
Similar Threads
-
Help with dox matrix printer
By Albert in forum Advanced JavaReplies: 7Last Post: 09-06-2011, 08:50 AM -
How to print text file in java(dotmatrix printer)
By yoganeethi in forum Advanced JavaReplies: 4Last Post: 12-01-2010, 01:45 PM -
Need help with POS printer
By bkirt in forum Java 2DReplies: 13Last Post: 08-29-2010, 11:11 PM -
Specifying a Network Printer in Printer Servlet
By shapez in forum New To JavaReplies: 0Last Post: 03-06-2008, 03:21 PM -
please help on java program for printer : this printer is connected to system which
By for453 in forum Java 2DReplies: 0Last Post: 08-09-2007, 06:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks