• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Print Problem  RSS feed

 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Could someone please assist me to print the rtf file using java code

I tried the below code. But only working for txt not for rtf.. I just want to print the data in the exact format and exact font style. Please assist

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I doubt that many (or any) printers know what to do with RTF files. You'll need to find an application that does, like OpenOffice (which has a Java API), und use that for printing.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its confirmed Java not supporting rtf and doc.. Please assist me with some other API
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try using a JEditorPane and use one of its print methods:
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assist me with some examples.. Unable to pass the rtf file path.. I need the print output with exact text format and font styles
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The hard part is that JEditorPane only accepts strings or URLs. One way is to read the contents of the file into a StringBuilder, then call its toString() method. The easier way is to convert a File into a URL:

Although it can't handle objects like images or embedded Office documents, simple text including the format should not be a problem.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No method like pane.print();
Only pane.print(graphics); is available. How to use this please assist me
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The print methods have only been introduced in Java 6. I suggest you upgrade to that version.

Alternatively you could implement your own Printable implementation:

This is a very naive approach implementation though, since it doesn't paginate at all - it will try to print everything on a single page.
In a proper solution, you need to calculate on which part of the pane to print based on the page. Hint: use graphics.translate() for that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!