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 [email protected]:
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: [email protected]
For additional commands, e-mail: [email protected]



/*
 * 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.logging.Level;
import java.util.logging.Logger;

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

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

    /**
     * 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() {

        find_file_contaiiner = new javax.swing.JPanel();
        find_file_menu = new javax.swing.JFileChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        find_file_menu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                find_file_menuActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout find_file_contaiinerLayout = new 
javax.swing.GroupLayout(find_file_contaiiner);
        find_file_contaiiner.setLayout(find_file_contaiinerLayout);
        find_file_contaiinerLayout.setHorizontalGroup(
            
find_file_contaiinerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(find_file_contaiinerLayout.createSequentialGroup()
                .addComponent(find_file_menu, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        find_file_contaiinerLayout.setVerticalGroup(
            
find_file_contaiinerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(find_file_contaiinerLayout.createSequentialGroup()
                .addComponent(find_file_menu, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

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

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

    private void find_file_menuActionPerformed(java.awt.event.ActionEvent evt) 
{                                               
        if (find_file_menu.isAcceptAllFileFilterUsed()) {
            File filePath = find_file_menu.getSelectedFile(); 
            PrepareFile sendToPrepare = new PrepareFile(filePath);
            try {
                sendToPrepare.preparePdf();
            } catch (IOException ex) {
                Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, 
null, ex);
            }
        }
    }                                              

    /**
     * @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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
 null, ex);
        } catch (InstantiationException ex) {
            
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
 null, ex);
        } catch (IllegalAccessException ex) {
            
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
 null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            
java.util.logging.Logger.getLogger(NewJFrame.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() {
                new NewJFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JPanel find_file_contaiiner;
    private javax.swing.JFileChooser find_file_menu;
    // End of variables declaration                   
}

/*
 * 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.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import java.util.List;

/**
 *
 * @author gerry
 */
public class PrepareFile {
    File inputFile;
    
    
    public PrepareFile(File inputFile){
        this.inputFile = inputFile;
    }
    public void preparePdf()throws IOException{
        PDDocument inputPDF = PDDocument.load(inputFile);
        List<PDPage> allPages = inputPDF.getDocumentCatalog().getAllPages();
        PDPage testPage = (PDPage)allPages.get(0);
        pdfViewer pdfviewer = new pdfViewer();
        pdfviewer.Screen(testPage);
        pdfviewer.setVisible(true);
        inputPDF.close();
        
    }
   
}

/*
 * 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.awt.Component;
import java.io.IOException;
import org.apache.pdfbox.pdfviewer.PDFPagePanel;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import java.awt.image.BufferedImage;
import javax.swing.BoxLayout;

/**
 *
 * @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(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>                        

    /**
     * @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() {
                new pdfViewer().setVisible(true);
            }
        });
    }

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to