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

Displaying pdf and rtf files  RSS feed

 
Yogesh Pavan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm developing an application that could display most of the document formats. Currently i've created seperate clases for pdf and rtf. But i want to view pdf and rtf files in a single window based upon extensions either pdf or rtf. The codes for rtf and pdf are here given below:

This is for rtf:



I've struck with this one.
Please help, thanks in advance..
 
Tim Moores
Saloon Keeper
Posts: 3511
77
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TL;DR

It's unlikely you'll make this work within the exact same Swing component. The RTFEditorKit class (and its related classes) can't handle PDFs; for that you'll need a library like PDFRenderer. But if you use a parent JPanel for the display component, then you can add and remove the actual display component for each file format as needed.

Note that it gets harder after RTF and PDF - for example, there's no freely available component for DOC/DOCX files. And RTFEditorKit is limited and buggy. Just as an up-front warning to set expectations properly :-)
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:TL;DR

Definitely. If you're having problem with a piece of code you should condense it into an SSCCE.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TL;DR++

Rather than add/remove components, you might use a CardLayout.
 
Yogesh Pavan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:TL;DR

It's unlikely you'll make this work within the exact same Swing component. The RTFEditorKit class (and its related classes) can't handle PDFs; for that you'll need a library like PDFRenderer. But if you use a parent JPanel for the display component, then you can add and remove the actual display component for each file format as needed.

Note that it gets harder after RTF and PDF - for example, there's no freely available component for DOC/DOCX files. And RTFEditorKit is limited and buggy. Just as an up-front warning to set expectations properly :-)


Thanks for the response.
You're right, there's no freely available component for doc/docx files. But are there any classes available for odt(opendocument) files.?
I'm trying with HtmlProcessor class to display html docs. I'll try with the PDFRenderer and RTFEditorKit now for pdf and rtf docs.
 
Yogesh Pavan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:
Tim Moores wrote:TL;DR

Definitely. If you're having problem with a piece of code you should condense it into an SSCCE.


Thank you, i'll condense it into an SSCCE.
 
Yogesh Pavan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:TL;DR++

Rather than add/remove components, you might use a CardLayout.


Thanks for the response, i'll use CardLayout here.
 
Tim Moores
Saloon Keeper
Posts: 3511
77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Apache POI library can read DOC and DOCX files, but it'll be a LOT of work to build a component on top of that which can display such files properly formatted in Swing. Probably a month of work until you have something that's not very elaborate. There may be commercial components you could buy for less, though.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!