Foros del Web » Programación para mayores de 30 ;) » Java »

libreria pdf-renderer dentro de un jpanel

Estas en el tema de libreria pdf-renderer dentro de un jpanel en el foro de Java en Foros del Web. Hola como estan.. estoy tratando de hacer una vista previa de un pdf.. dentro de un jsplitpane... dentro del mismo ..quiero meter un visor de ...
  #1 (permalink)  
Antiguo 04/09/2014, 09:11
 
Fecha de Ingreso: enero-2007
Mensajes: 285
Antigüedad: 17 años, 3 meses
Puntos: 21
libreria pdf-renderer dentro de un jpanel

Hola como estan.. estoy tratando de hacer una vista previa de un pdf.. dentro de un jsplitpane... dentro del mismo ..quiero meter un visor de pdf que es pdf-renderer.jar.

https://java.net/projects/pdf-renderer

segun el ejemplo de la pagina... al hacer esto anda.. y es verdad..

Código:
public class NewClass {

    public void setup() throws IOException {
    
        //set up the frame and panel
        JFrame frame = new JFrame("PDF Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        PagePanel panel = new PagePanel();
        frame.add(panel);
        frame.pack();
      
        frame.setVisible(true);

        //load a pdf from a byte buffer
        File file = new File("C:/1.pdf");
        RandomAccessFile raf = new RandomAccessFile(file, "r");
        FileChannel channel = raf.getChannel();
        ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
        PDFFile pdffile = new PDFFile(buf);

        // show the first page
        PDFPage page = pdffile.getPage(0);
        panel.showPage(page);
        
     
        
    }

    public static void main(final String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                try {
                    NewClass nc=new NewClass();
                            nc.setup();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        });
    }
}
pero cuando quiero poner el pagepanel en el jsplit pane.. deja de andar.. me dice.. NO PAGE SELECTED. por lo visto.. el truco esta donde hacer el pack.. pero no lo pude resolver.

si alguno tiene idea de como solucionarlo se lo agradeceria.
  #2 (permalink)  
Antiguo 04/09/2014, 11:47
 
Fecha de Ingreso: enero-2007
Mensajes: 285
Antigüedad: 17 años, 3 meses
Puntos: 21
Respuesta: libreria pdf-renderer dentro de un jpanel

GENTE.. COMO VA?

bueno .. por el momento lo resolvi.. por medio de un hilo.. y con un sleep antes de mostrar la hora.. si alguien tiene una mejor opcion.. leo sugerencias..

Código:
private void setup() {

   Thread thread = new Thread(new Runnable() {
            public void run() {
                try {
                    PagePanel panel = new PagePanel();



                   add(panel);
                   panel.repaint();
                   panel.validate();



                   //load a pdf from a byte buffer
                   File file = new File(pdfFile);
                   RandomAccessFile raf = new RandomAccessFile(file, "r");
                   FileChannel channel = raf.getChannel();
                   ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
                   PDFFile pdffile = new PDFFile(buf);

                   // show the first page
                    PDFPage page = pdffile.getPage(0);

                    Thread.sleep(100);
     

                   panel.showPage(page);
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(vistaPrevia2.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(vistaPrevia2.class.getName()).log(Level.SEVERE, null, ex);
                } catch (InterruptedException ex) {
                    Logger.getLogger(vistaPrevia2.class.getName()).log(Level.SEVERE, null, ex);
                }

  }
        });
        thread.start();

    }

Etiquetas: jframe, jpanel, libreria, string
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:22.