• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Open a file for view

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}
}
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic