Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Open a file for view  RSS feed

 
Patrick Mugabe
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using itext and I have created a PDF file which I save to my c drive (c:\iText\File.pdf). I now want to open it from my java program. I want to pass the file name and open it. How do I do it? The code below just passes the fileName but I don't know how to open it.

public final void openPDF ()
{
String fileName = "C:\\iText\\File.pdf"
FileInputStream fis;

try
{
fis = new FileInputStream (fileName);

//Here I want to open the file???

fis.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "open"? FileInputStream will get you the bytes, but you probably won't be able to do anything meaningful with it. iText lets you open PDF files and do a few things with them. If you want to display it, use Runtime.exec to call the AcrobatReader executable and pass along the filename, or you can use the Acrobat Viewer JavaBean.
[ August 24, 2006: Message edited by: Ulf Dittmer ]
 
Patrick Mugabe
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I have used:

public final void openPDF ()
{
try{
Runtime.getRuntime().exec("rundll32
url.dll,FileProtocolHandler " + fileName);
}catch(Exception e){
System.out.println("Failed to open file ");
}

}

It works well on Windows. I am not sure though if this is the best way.
Is there another way? I will look at Accessing a PDF Document with the Acrobat Viewer JavaBean as you indicated. I would want to open it from my java program.
[ August 24, 2006: Message edited by: Patrick Mugabe ]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!