You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by "gerryw@hispeed.ch" <ge...@hispeed.ch> on 2015/12/26 17:13:18 UTC

can not get file to display

Hi

I am trying to get a pdf file to display using pdfbox.

I can only get a plain box.

I am not sure what I am doing wrong, I have attached the two files to 
this email, please forgive me if I have got something wrong I am just a 
beginner.

Any help gratefully received.

Gerry

Re: can not get file to display

Posted by Tilman Hausherr <TH...@t-online.de>.
Here's some 1.8 code that "almost" works, i.e. it does display a PDF 
page from a fixed file. There's still a problem with the GUI elements, 
the two "super.add()" are probably not correct. It is reduced from your 
code.

- don't close PDF file
- static object
- loadNonSeq

==============

/*
  * To change this license header, choose License Headers in Project 
Properties.
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
package pdfhighlighter.gui;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.pdfbox.pdfviewer.PDFPagePanel;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;

/**
  *
  * @author gerry
  */
public class pdfViewer extends javax.swing.JFrame
{

     /**
      * Creates new form pdfViewer
      */
     public pdfViewer()
     {
         super();
         initComponents();
     }

     public void Screen(PDPage testPage) throws IOException
     {
         PDFPagePanel pagePanel = new PDFPagePanel();
         pagePanel.setPage(testPage);
         pagePanel.getFont();
         pagePanel.setVisible(true);

         viewingPanel.add(pagePanel);
         viewingPanel.setBounds(40, 40, pagePanel.getWidth(), 
pagePanel.getHeight());
         viewingPanel.setVisible(true);
         super.add(pagePanel);
         super.add(viewingPanel);

     }

     /**
      * This method is called from within the constructor to initialize 
the form. WARNING: Do NOT
      * modify this code. The content of this method is always 
regenerated by the Form Editor.
      */
     @SuppressWarnings("unchecked")
     // <editor-fold defaultstate="collapsed" desc="Generated Code">
     private void initComponents()
     {

         viewingPanel = new javax.swing.JScrollPane();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

         javax.swing.GroupLayout layout = new 
javax.swing.GroupLayout(getContentPane());
         getContentPane().setLayout(layout);
         layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                 .addComponent(viewingPanel, 
javax.swing.GroupLayout.DEFAULT_SIZE, 573, Short.MAX_VALUE)
         );
         layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                 .addComponent(viewingPanel, 
javax.swing.GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE)
         );

         pack();
     }// </editor-fold>

     static PDDocument inputPDF;

     /**
      * @param args the command line arguments
      */
     public static void main(String args[])
     {
         /* Set the Nimbus look and feel */
         //<editor-fold defaultstate="collapsed" desc=" Look and feel 
setting code (optional) ">
         /* If Nimbus (introduced in Java SE 6) is not available, stay 
with the default look and feel.
          * For details see 
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
          */
         try
         {
             for (javax.swing.UIManager.LookAndFeelInfo info : 
javax.swing.UIManager.getInstalledLookAndFeels())
             {
                 if ("Nimbus".equals(info.getName()))
                 {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
                     break;
                 }
             }
         }
         catch (ClassNotFoundException ex)
         {
java.util.logging.Logger.getLogger(pdfViewer.class.getName()).log(java.util.logging.Level.SEVERE, 
null, ex);
         }
         catch (InstantiationException ex)
         {
java.util.logging.Logger.getLogger(pdfViewer.class.getName()).log(java.util.logging.Level.SEVERE, 
null, ex);
         }
         catch (IllegalAccessException ex)
         {
java.util.logging.Logger.getLogger(pdfViewer.class.getName()).log(java.util.logging.Level.SEVERE, 
null, ex);
         }
         catch (javax.swing.UnsupportedLookAndFeelException ex)
         {
java.util.logging.Logger.getLogger(pdfViewer.class.getName()).log(java.util.logging.Level.SEVERE, 
null, ex);
         }
         //</editor-fold>

         /* Create and display the form */
         java.awt.EventQueue.invokeLater(new Runnable()
         {
             public void run()
             {
                 try
                 {
                     inputPDF = PDDocument.loadNonSeq(new 
File("blah.pdf"), null);
                     List<PDPage> allPages = 
inputPDF.getDocumentCatalog().getAllPages();
                     PDPage testPage = allPages.get(0);
                     pdfViewer pdfviewer = new pdfViewer();
                     pdfviewer.Screen(testPage);
                     pdfviewer.setVisible(true);
                 }
                 catch (IOException ex)
                 {
Logger.getLogger(pdfViewer.class.getName()).log(Level.SEVERE, null, ex);
                 }
             }
         });
     }

     // Variables declaration - do not modify
     private javax.swing.JScrollPane viewingPanel;
     // End of variables declaration
}


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: can not get file to display

Posted by Tilman Hausherr <TH...@t-online.de>.
OK, good luck. Sorry I couldn't help much. Btw if you're just starting, 
I recommend you to go right to 2.0, as 1.8.10 has display problems with 
many files. For GUI applications, see in the source code of PDFDebugger 
how to display.

Tilman

Am 26.12.2015 um 20:58 schrieb gerryw@hispeed.ch:
> Hi Tilman
>
> I managed to open it from the command line so I am going to play with 
> that.
>
> Again thank you very much for your help.
>
> I will let you know if I have any success.
>
> Gerry 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: can not get file to display

Posted by "gerryw@hispeed.ch" <ge...@hispeed.ch>.
Hi Tilman

I managed to open it from the command line so I am going to play with that.

Again thank you very much for your help.

I will let you know if I have any success.

Gerry

On 12/26/2015 08:48 PM, Tilman Hausherr wrote:
> Hi,
>
> I doubt you're using 2.0 - PDFPagePanel does not exist in 2.0.
>
> Your code now has three classes, two of them have a "main", and two of 
> them extend "JFrame". I assume that "NewJFrame" is the one to start.
>
> You're closing the document while it is displayed. Even if I remove 
> that line "inputPDF.close();", the document is still being closed 
> (that is the warning "You did not close a PDF Document").
>
> I suspect you're "losing" some object that (indirectly) holds the 
> PDDocument object. I did manage to avoid the effect by keeping this 
> object as static, but even I can't display the page :-(
>
> The problem is that I'm not a java GUI specialist. Last time we needed 
> such expertise, we hired a guy and google paid the bill (Google summer 
> of code 2015).
>
> Tilman
>
>
> Am 26.12.2015 um 18:44 schrieb gerryw@hispeed.ch:
>> Hi
>>
>> Thank you for your kind reply.
>>
>> Sorry that my code was incomplete, I have attached a fuller version 
>> to this message.
>>
>> I am using  2.0.0 .
>>
>> When you say "PrepareFile is never constructed " . The constructor is 
>> in the file or am I missing something?
>>
>> Kind Regards
>>
>> Gerry
>>
>> On 12/26/2015 06:09 PM, Tilman Hausherr wrote:
>>> Hi,
>>>
>>> Assuming that you are using 1.8.10, use the PDFReader command line 
>>> application to check that PDFbox 1.8.10 can display your file.
>>>
>>> The code you attached is incomplete. The imports and (probably) the 
>>> line "public class pdfViewer extends JFrame {" is missing.
>>>
>>> PrepareFile is never constructed. (Maybe that too, is in the missing 
>>> lines - maybe some static code?)
>>>
>>> Tilman
>>>
>>> Am 26.12.2015 um 17:13 schrieb gerryw@hispeed.ch:
>>>> Hi
>>>>
>>>> I am trying to get a pdf file to display using pdfbox.
>>>>
>>>> I can only get a plain box.
>>>>
>>>> I am not sure what I am doing wrong, I have attached the two files 
>>>> to this email, please forgive me if I have got something wrong I am 
>>>> just a beginner.
>>>>
>>>> Any help gratefully received.
>>>>
>>>> Gerry
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: can not get file to display

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,

I doubt you're using 2.0 - PDFPagePanel does not exist in 2.0.

Your code now has three classes, two of them have a "main", and two of 
them extend "JFrame". I assume that "NewJFrame" is the one to start.

You're closing the document while it is displayed. Even if I remove that 
line "inputPDF.close();", the document is still being closed (that is 
the warning "You did not close a PDF Document").

I suspect you're "losing" some object that (indirectly) holds the 
PDDocument object. I did manage to avoid the effect by keeping this 
object as static, but even I can't display the page :-(

The problem is that I'm not a java GUI specialist. Last time we needed 
such expertise, we hired a guy and google paid the bill (Google summer 
of code 2015).

Tilman


Am 26.12.2015 um 18:44 schrieb gerryw@hispeed.ch:
> Hi
>
> Thank you for your kind reply.
>
> Sorry that my code was incomplete, I have attached a fuller version to 
> this message.
>
> I am using  2.0.0 .
>
> When you say "PrepareFile is never constructed " . The constructor is 
> in the file or am I missing something?
>
> Kind Regards
>
> Gerry
>
> On 12/26/2015 06:09 PM, Tilman Hausherr wrote:
>> Hi,
>>
>> Assuming that you are using 1.8.10, use the PDFReader command line 
>> application to check that PDFbox 1.8.10 can display your file.
>>
>> The code you attached is incomplete. The imports and (probably) the 
>> line "public class pdfViewer extends JFrame {" is missing.
>>
>> PrepareFile is never constructed. (Maybe that too, is in the missing 
>> lines - maybe some static code?)
>>
>> Tilman
>>
>> Am 26.12.2015 um 17:13 schrieb gerryw@hispeed.ch:
>>> Hi
>>>
>>> I am trying to get a pdf file to display using pdfbox.
>>>
>>> I can only get a plain box.
>>>
>>> I am not sure what I am doing wrong, I have attached the two files 
>>> to this email, please forgive me if I have got something wrong I am 
>>> just a beginner.
>>>
>>> Any help gratefully received.
>>>
>>> Gerry
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org


Re: can not get file to display

Posted by "gerryw@hispeed.ch" <ge...@hispeed.ch>.
Hi

Thank you for your kind reply.

Sorry that my code was incomplete, I have attached a fuller version to 
this message.

I am using  2.0.0 .

When you say "PrepareFile is never constructed " . The constructor is in 
the file or am I missing something?

Kind Regards

Gerry

On 12/26/2015 06:09 PM, Tilman Hausherr wrote:
> Hi,
>
> Assuming that you are using 1.8.10, use the PDFReader command line 
> application to check that PDFbox 1.8.10 can display your file.
>
> The code you attached is incomplete. The imports and (probably) the 
> line "public class pdfViewer extends JFrame {" is missing.
>
> PrepareFile is never constructed. (Maybe that too, is in the missing 
> lines - maybe some static code?)
>
> Tilman
>
> Am 26.12.2015 um 17:13 schrieb gerryw@hispeed.ch:
>> Hi
>>
>> I am trying to get a pdf file to display using pdfbox.
>>
>> I can only get a plain box.
>>
>> I am not sure what I am doing wrong, I have attached the two files to 
>> this email, please forgive me if I have got something wrong I am just 
>> a beginner.
>>
>> Any help gratefully received.
>>
>> Gerry
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>


Re: can not get file to display

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,

Assuming that you are using 1.8.10, use the PDFReader command line 
application to check that PDFbox 1.8.10 can display your file.

The code you attached is incomplete. The imports and (probably) the line 
"public class pdfViewer extends JFrame {" is missing.

PrepareFile is never constructed. (Maybe that too, is in the missing 
lines - maybe some static code?)

Tilman

Am 26.12.2015 um 17:13 schrieb gerryw@hispeed.ch:
> Hi
>
> I am trying to get a pdf file to display using pdfbox.
>
> I can only get a plain box.
>
> I am not sure what I am doing wrong, I have attached the two files to 
> this email, please forgive me if I have got something wrong I am just 
> a beginner.
>
> Any help gratefully received.
>
> Gerry
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org