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
 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                   
}

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;
    PDPage testPage;
    
    public PrepareFile(File inputFile){
        this.inputFile = inputFile;
    }
    public void preparePdf()throws IOException{
        PDDocument inputPDF = PDDocument.load(inputFile);
        List<PDPage> allPages = inputPDF.getDocumentCatalog().getAllPages();
        this.testPage = (PDPage)allPages.get(0);
        pdfViewer pdfviewer = new pdfViewer();
        pdfviewer.Screen(testPage);
        pdfviewer.setVisible(true);
        inputPDF.close();
        
    }
    public PDPage getInput(){
        return this.testPage;
    }
}

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

Reply via email to