Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display a PDF file

Status
Not open for further replies.

RedLion

Programmer
Sep 13, 2000
342
0
0
NL
Hello,

I would like to open a pdf file from my application, so the users can read it when they press the HELP button on my frame. If it is possible I would like to open it in a frame so I can set the same icon and title for it as my application has.


Thanks in advance,

Charl
 
there is an object called jEditorPane. it's designed for text/html/rtf, but most things that can display htmlcan display pdf. if it can't, then how about making a html that displays the pdf and just displaying said html? here's some code, not tested:

try{
//new window, pdf (well, html) viewer, and a sroll box
JFrame myFrame = new JFrame("window title goes here");
JEditorPane myPDF = new JEditorPane("help.pdf");
JScrollPane myScroll = new JScrollPane(myPDF);

//set the preferred width as high as you like
myScroll.setPreferredSize(new Dimension(450, 0));
myPDF.setEditable(false);

//usual new frame gumph
myFrame.setContentPane(myScroll);
myFrame.setDefaultCloseOperatio(JFrame.DISPOSE_ON_CLOSE);
//notice width here is same as myScroll
myFrame.setSize(450, 600);
myFrame.setVisible(true);
}
catch(IOException e){
//displays an error box if the file is not found
JOptionPane.showConfirmDialog(TuringMachine.this, "Help file not found", "Allen says...", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
}
 
- JOptionPane.showConfirmDialog was taken from a turing machine simulator i made once, i negleted to change the information passed but i'm sure you'll work it out.
 
Thanks for your quick response Seanbo!

I had to change a few things to make it work, but the problem is that it displays the pdf file binairy, so it is unreadable for a user.

How can I display a pdf file in a frame readable for a user?


Thanks in advance,

Charl
 
did you just add the pdf file to the JEditorPane? or did you first create a html page that displays the pdf?
 
Just to the JEditorPane.

How do you see it, create a html page that displays the pdf?
 
that was my thinking (i assume you can create a html that displays a pdf, i'm pretty sure i've seen them around the place).
 
I think the solution is to convert the pdf file to an html page and then the jEditorPane will treat it like a URL.
i.e wasPDF.htm => yourEditorPane.setPage(asPDF.htm);

I just did something like this at work for the help dialog of our current release. I modified a tutorial I found at java.sun.com; since the API does NOT have a browser class per se; I had to build one from scratch.

Good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top