• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Java Print Problem

 
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its confirmed Java not supporting rtf and doc.. Please assist me with some other API
 
Sheriff
Posts: 22809
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22809
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22809
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I guess everyone has an angle. Fine, what do you want? Just know that you cannot have this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic