0

Im trying to open a pdf document, using PDFBox, but the pdf does not open. When I click the button the PDF should be displayed on the screen.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
         try {
             PDDocument document = null;
             document = PDDocument.load(new File("C:/Users/Warcross.pdf"));
             document.close();
         } catch (IOException ex) {
             Logger.getLogger(InfoDelLibro.class.getName()).log(Level.SEVERE, null, ex);

         }

    }        

Shean98
  • 13
  • 3
  • Which exception do you get? – WoAiNii Jun 16 '20 at 18:11
  • When i click the button, the document does not open, does not throw exceptions :(. I think i should add another line of code, to show the pdf – Shean98 Jun 16 '20 at 18:16
  • If you debug your code, the action is called? Can you post a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example)? – WoAiNii Jun 16 '20 at 18:19
  • What do you expect to happen? When you say "the pdf does not open", I somehow suspect that you expect the document to be displayed on your screen... – Axel Jun 16 '20 at 18:36
  • Yes, it should be displayed on the screen. When I click the button, the PDF will be displayed on the screen – Shean98 Jun 16 '20 at 18:58
  • 1
    *"When I click the button, the PDF will be displayed on the screen "* - Not with your code. `PDDocument.load` merely loads the pdf into memory for further processing. – mkl Jun 16 '20 at 19:09
  • @mkl Yes, but, how can I retrieve the pdf that is in memory and display it on the screen? – Shean98 Jun 16 '20 at 19:13
  • First convert it to image https://stackoverflow.com/questions/23326562/ then display that one. Alternatively get the sources of PDFReader / PDFDebugger from the source code download. – Tilman Hausherr Jun 17 '20 at 03:58
  • 1
    Depending on what you're trying to acomplish, I'd suggest you first create an application that displays a BufferedImage in your application. When that works, then do it with a PDF. I also recommend you use 2.*, not 1.8 if you're starting from scratch. – Tilman Hausherr Jun 17 '20 at 08:50

0 Answers0