0

How to open a pdf file in JButton action performed, My code is

try
    {
       Runtime.getRuntime().exec("rundll32 url.dll, FileProtocolHandler " + "C:\\Users\\Thini\\Desktop\\Dictionary Application\\src\\Wall_images\\History word doc.pdf");
    }
    catch (Exception e)
    {
        JOptionPane.showMessageDialog(null, "Check file details");
    }

Its work perfectly, but when i compile and run that programme another PC - its nothing happen

didn't work

How can i fixed this???

@@ How to attached my pdf ??

  • Does the document on the other PC also exists on the exact same path? Will it be always the same PDF? In this case include it in the resources (see e.g. https://stackoverflow.com/questions/3861989/preferred-way-of-loading-resources-in-java) – Joachim Rohde Dec 04 '19 at 08:56

1 Answers1

0

You Can Use file chooser or ProcessBuilder

Two parts in there

  1. Use the file chooser to select a file (you already got that)
  2. Then use that file name with either some Java component that is able to open/present the PDF file; or use javas See Here ProcessBuilder to start a new external process that uses some tool like Adobe Reader to open that file.

    you can check more example about open pdf Here

Kiran Mistry
  • 2,614
  • 3
  • 12
  • 28