Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

PRINTING to File (as in PRN files).  RSS feed

 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just when you got it, they change the requirements
Seriously, now that I had Java applications printing JTextPanes in any kind of printer (with the use of 3rd party software from Wildcrest Associates), they now want me to print to a file.
That is not saving a file which is almost trivial using a FileWriter, but saving the actual PRN file to disk.
A Windows PRN file contains the actual instruction to the printer. For example, one begins like this:

and is followed by obviously binary code.
I suspect this is not going to be easy from a Java app since it seems that it's an OS-specific function; I would hate to hear "JNI"!
Has anybody had this requirement before!?
Thanks
Tony
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anybody had this requirement before!?
Not me. No idea how PRN files work.
I would hate to hear "JNI"!
Would you prefer Runtime.getRuntime().exec()?
Not that I know what command to exec, but I suspect that the solution will involve either JNI or exec().
However, is it possible you can just serialize the JTextPane? (Subject to the usual caveat: "Serialized objects of this class will not be compatible with future Swing releases...") Or just write a file with the contents of the text pane (possibly including stuff like component size and position), with enough info to regenerate the pane later?
If indeed you need to create a PRN file, sorry, can't help. Good luck.
[ November 24, 2003: Message edited by: Jim Yingst ]
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jim...
Well, it turned out to be simpler than expected if you use the new (with JDK 1.4) Print Service API that consists of the packages:

To make a long story short, from the class javax.print.attribute.standard.Destination:
"A common use for this attribute will be applications which want to redirect output to a local disk file: eg."file: out.prn". Note that proper construction of "file:" scheme URI instances should be performed using the toURI() method of class File. See the documentation on that class for more information."
Now, I told my director: "The operation was a success but the patient died"
That's because IBM's WebSphere app server version 5 uses JDK 1.3!!
And my web app runs on WesbSphere
Oh well, some other dude decide how to upgrade WebSphere to the latest JDK... probably not me!
Or else go back to straight printing... (There are good reasons for us to create a PRN file which I won't go into here.)
---
Tony
[ November 25, 2003: Message edited by: Tony Alicea ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh well, some other dude decide how to upgrade WebSphere to the latest JDK... probably not me!
They'll probably upgrade to 1.4 right after 1.5 is released.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Double check your IBM support for 1.4. There was some discussion in another forum that some IBM packages (portlets or e-selling or something) came with 1.4 which seemed to imply the server will run with it.
Can you run a POJO 1.4 process on the same machine? Of course then you'd hav eto figure out how to talk to it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!