I want to display pdf files from within java
1) I can use getruntime().exec
BUT I need to know the external pdf viewers name
2) I can use the java viewer from Adobe 1998
This crashed wanting com.apple.mrj
So I paid $26 to Limeware to get the MRJ stubs
And I get an internal viewer
BUT it shows an initial Adobe licence screen every time,
its very slow
it crashed one time with java heap error
everytime it closes it tries to write a profile,
fails and displays an error
NOT a pleasant experience.
(if you do want those MRJ stubs, email me, I will send them to you
dont pay $26 to Limeware)
If I choose option 1, On Windows I must delve into the registry to find
the default pdf viewer [this seems retrograde, not truly
WriteOnceRunAnyware]
If Linux How do I find the default pdf handler from within Java?
I personally believe its a waste of time. Better to let the user click
on pdf files in an external fileviewer.
But my manager wants my program to show pdfs, and he pays my wage.
Is there an easy way?
cheers
gbruno
Andrey Kuznetsov - 10 Jun 2005 09:17 GMT
>I want to display pdf files from within java
http://www.google.de/search?hl=de&q=pdf+viewer+java&btnG=Google-Suche&meta=

Signature
Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities
Bill Tschumy - 10 Jun 2005 17:12 GMT
> I want to display pdf files from within java
>
[quoted text clipped - 27 lines]
> cheers
> gbruno
You are going about it the hard way. Look at:
< http://www.javaworld.com/javaworld/javatips/jw-javatip66.html>
This code is austensibly to open a url in a browser, but on Windows it will
open any file type using the application registered for that file type
(including PDF!!).
I have augmented the code to work on Mac OS X. Here is the final version:
import java.io.*;
import java.net.*;
/**
* A simple, static class to display a URL in the system browser.
*
*
*
* Under Unix, the system browser is hard-coded to be 'netscape'.
* Netscape must be in your PATH for this to work. This has been
* tested with the following platforms: AIX, HP-UX and Solaris.
*
*
*
* Under Windows, this will bring up the default browser under windows,
* usually either Netscape or Microsoft IE. The default browser is
* determined by the OS. This has been tested under Windows 95/98/NT.
*
*
*
* Examples:
*
*
* BrowserControl.displayURL("http://www.javaworld.com")
*
* BrowserControl.displayURL("file://c:\\docs\\index.html")
*
* BrowserContorl.displayURL("file:///user/joe/index.html");
*
*
* Note - you must include the url type -- either "http://" or "file://".
*
* Taken from JavaWorld Tip #66 by Steven Spencer
*
*/
public class BrowserControl
{
// Used to identify the windows platform.
private static final String WIN_ID = "Windows";
// Used to identify the mac platform.
private static final String MAC_ID = "Mac";
// The default system browser under windows.
private static final String WIN_PATH = "rundll32";
// The flag to display a url.
private static final String WIN_FLAG = "url.dll,FileProtocolHandler";
// The default browser under unix.
private static final String UNIX_PATH = "netscape";
// The flag to display a url.
private static final String UNIX_FLAG = "-remote openURL";
/**
* Display a file in the system browser. If you want to display a
* file, you must include the absolute path name.
*
* @param url the file's url (the url must start with either "http://" or
* "file://").
*/
public static void displayURL(String url)
{
boolean windows = isWindowsPlatform();
boolean mac = isMacPlatform();
String cmd = null;
// Different OS's and Java versions pass different things as the
// file: url. We need to get it in the form of file:/// for it to
// launch correctly on all platforms.
if (url.indexOf("file:///") == 0)
{
//everything is fine
}
else if (url.indexOf("file://") == 0)
url = Utility.replaceAll("file://", "file:///", url);
else if (url.indexOf("file:/") == 0)
url = Utility.replaceAll("file:/", "file:///", url);
else if (url.indexOf("file:") == 0)
url = Utility.replaceAll("file:", "file:///", url);
if (isMacPlatform())
{
url = Utility.replaceAll(" ", "%20", url);
}
if (url.startsWith("file:"))
url = Utility.replaceAll("?", "%3F", url);
//System.out.println("displaying: " + url);
try
{
if (windows)
{
// cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
Process p = Runtime.getRuntime().exec(cmd);
}
else if (mac)
{
Runtime.getRuntime().exec(new String[] {"open", url });
}
else
{
String browser = System.getProperty("BrowserCmd");
if (browser != null)
{
Runtime.getRuntime().exec(new String[] {(String) browser,
url });
}
else
{
// Under Unix, Netscape has to be running for the
"-remote"
// command to work. So, we try sending the command and
// check for an exit value. If the exit command is 0,
// it worked, otherwise we need to start the browser.
// cmd = 'netscape -remote
openURL(http://www.javaworld.com)'
cmd = UNIX_PATH + " " + UNIX_FLAG + "(" + url + ")";
Process p = Runtime.getRuntime().exec(cmd);
try
{
// wait for exit code -- if it's 0, command worked,
// otherwise we need to start the browser up.
int exitCode = p.waitFor();
if (exitCode != 0)
{
// Command failed, start up the browser
// cmd = 'netscape http://www.javaworld.com'
cmd = UNIX_PATH + " " + url;
p = Runtime.getRuntime().exec(cmd);
}
}
catch(InterruptedException e)
{
System.err.println("Error bringing up browser, cmd='"
+
cmd + "'");
System.err.println("Caught: " + e);
}
}
}
}
catch (IOException e)
{
// couldn't exec browser
System.err.println("Could not invoke browser, command=" + cmd);
System.err.println("Caught: " + e);
}
}
/**
* Try to determine whether this application is running under Windows
* or some other platform by examing the "os.name" property.
*
* @return true if this application is running under a Windows OS
*/
public static boolean isWindowsPlatform()
{
String os = System.getProperty("os.name");
if ( os != null && os.startsWith(WIN_ID))
return true;
else
return false;
}
public static boolean isMacPlatform()
{
String os = System.getProperty("os.name");
if ( os != null && os.startsWith(MAC_ID))
return true;
else
return false;
}
/**
* Simple example.
*/
public static void main(String[] args)
{
displayURL("http://www.javaworld.com");
}
}

Signature
Bill Tschumy
Otherwise -- Austin, TX
http://www.otherwise.com
Richard Wheeldon - 15 Jun 2005 20:02 GMT
> I want to display pdf files from within java
3 more suggestions:
1. Go to http://www.jpedal.org/pdfviewer.html and
pay lots of money for something that works pretty
well.
2. Treat it as a URL (see post by Bill Tschumy)
3. Give up on PDFs and use something else. I moved
over to xsl:fo and used fop, but I only needed to
view reports that I'd generated, not 3rd party ones.
ymmv,
Richard
Joly Makunga - 30 Jun 2005 11:13 GMT
> I want to display pdf files from within java
>
[quoted text clipped - 27 lines]
> cheers
> gbruno
hi,
i'm french so i'm sorry for my english. i noticed that we work in the
same project. indeed we want to display pdf files by using java program.
we did some researchs and we found nothing usefull that allow us to
create our own program. we found many examples about the creation of pdf
files by using java, but nothing about the displaying. Now i have no
news, but if i find something we'll send it to you and i hope you'll do
the same for me.
see you online
jolyqr