Forums Register Login

Open a file for view

+Pie Number of slices to send: Send
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();
}
}
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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 ]
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1047 times.
Similar Threads
problem with download dialog box
Creating PDF file using FileOutputStream
how to retrieve images on a jsp page
Inserting an Image into the DataBase :
Opening Files
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 23:19:02.