aspose file tools*
The moose likes I/O and Streams and the fly likes printing in java 1.4 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "printing in java 1.4" Watch "printing in java 1.4" New topic
Author

printing in java 1.4

Mario A. Villamizar
Ranch Hand

Joined: Mar 14, 2002
Posts: 35
Hi,
I'm developing a text editor in java and I want to add the printing facility
I have seen many axamples of how to print text in java 1.4 and all of them use an FileInputStream(File) to print text; like this:

I wonder if it is possible to print using some how the text in the JTextPane (I'm using a JTextPane)or DefaultStyledDocument object related with this textPane instead of the FileInputStream, all this because if it happens that you create a new document but you haven't save it and you want to print it, how could you print it, if the fisical file doesn't exist yet?
I hope, I made myself clear. Any tips are welcome!!
Thanks in advance,


MA Villamizar
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
Disclaimer: I haven't tried this myself, but according the the JavaDoc, the "SimpleDoc" constructor takes three parameters:
-- Object printData
-- DocFlavor flavor
-- DocAttributeSet attributes
If you have character data, you can pass in a "String" for the first parameter and use "DocFlavor.STRING" as the flavor. You don't need an underlying file. You might play around with some of the other flavor.
Also, are you using the "DocFlavor.INPUT_STREAM" flavor? If you, keep in mind that there are lots of subclasses of "java.io.InputStream" that you can use. You could use a "StringBufferInputStream" [created using a String] and the "DocFlavor.INPUT_STREAM" flavor to get the same affect a described in the previous paragraph.
You'd have to play around with the different flavors to see how to use the DefaultStyledDocument as an input, but I'd be surprised if it weren't supported.
Jan Michael Soan
Ranch Hand

Joined: Feb 08, 2003
Posts: 36
We are doing the same but I'm using JTextArea instead, if you want try
this codes bellow, Hope that helps . . .
Jan Michael Soan
Ranch Hand

Joined: Feb 08, 2003
Posts: 36
Previously asked question :
http://www.coderanch.com/t/336367/GUI/java/Printing-JTextArea
Special thanks to my friend Tom Hill;
 
jQuery in Action, 2nd edition
 
subject: printing in java 1.4