0

I am trying to view PDF using but I am getting the following error: java.awt.HeadlessException

When I try It on local it works and the code is the following :


             
        
              String filePath = "C:\\Users\\user\\Desktop\\name.pdf";

                // build a controller
                SwingController controller = new SwingController();

                // Build a SwingViewFactory configured with the controller
                SwingViewBuilder factory = new SwingViewBuilder(controller);

                // Use the factory to build a JPanel that is pre-configured
                //with a complete, active Viewer UI.
                JPanel viewerComponentPanel = factory.buildViewerPanel();

                // add copy keyboard command
                ComponentKeyBinding.install(controller, viewerComponentPanel);

                // add interactive mouse link annotation support via callback
                controller.getDocumentViewController().setAnnotationCallback(
                      new org.icepdf.ri.common.MyAnnotationCallback(
                             controller.getDocumentViewController()));

                // Create a JFrame to display the panel in
                JFrame window = new JFrame("Using the Viewer Component");
                window.getContentPane().add(viewerComponentPanel);
                window.pack();
                window.setVisible(true);

                // Open a PDF document to view
                controller.openDocument(filePath);
            

but when i compile and install the war file on web sphere i get the above error . Note that WebSphere is installed on linux VM

MIX 21
  • 1
  • 1
    is your WebSphere box a server with no gui? – g00se Nov 07 '22 at 12:47
  • The Linux installation WebSphere runs on, is probably not using a graphical user interface and therefore running a "headless" JVM. See https://www.oracle.com/technical-resources/articles/javase/headless.html – Christoph Dahlen Nov 07 '22 at 12:49
  • I access websphere through 192.168.xx.xx so it should have gui – MIX 21 Nov 07 '22 at 12:51
  • 3
    The fact that it's got a LAN ip address is not relevant – g00se Nov 07 '22 at 12:55
  • So why on earth would you want to display PDFs on the servers display, if you are not even sure it has X11 and all the stuff installed (where you usually dont want that on a server...)? – Gyro Gearless Nov 07 '22 at 13:00
  • How to install non headless JVM – MIX 21 Nov 07 '22 at 13:01
  • When the user click on the document I need to allow to view the pdf instead of downloading it I am using jsf framework – MIX 21 Nov 07 '22 at 13:02
  • 1
    You need to avoid asking XY questions and instead [state your goal](https://technojeeves.com/index.php/aliasjava1/15-smart-questions) – g00se Nov 07 '22 at 13:02
  • Then you need to convert it 'to html' – g00se Nov 07 '22 at 13:03
  • How to convert it where the pdf is located on the server and i need to retrieve it first then after click show it – MIX 21 Nov 07 '22 at 13:05
  • 1
    It might be easier to get the browser to display it [inline](https://stackoverflow.com/questions/32476706/how-to-display-pdf-file-in-browser) – g00se Nov 07 '22 at 13:08
  • 1
    Easier ... and you will probably get a more accurate rendering of the original PDF. – Stephen C Nov 07 '22 at 13:10

0 Answers0