2012-10-17 65 views
0

我在查看PagePanel中的頁面時遇到問題,當嘗試顯示pdf時,發生錯誤「java.nio.BufferUnderflowException。」。在PagePanel中顯示pdf的問題

錯誤:

java.nio.BufferUnderflowException at java.nio.HeapByteBuffer.get(Unknown Source) at com.sun.pdfview.decode.RunLengthDecode.decode(RunLengthDecode.java:64) at com.sun.pdfview.decode.RunLengthDecode.decode(RunLengthDecode.java:96) at com.sun.pdfview.decode.PDFDecoder.decodeStream(PDFDecoder.java:134) at com.sun.pdfview.PDFObject.decodeStream(PDFObject.java:347) at com.sun.pdfview.PDFObject.getStream(PDFObject.java:261) at com.sun.pdfview.PDFObject.getStream(PDFObject.java:298) at com.sun.pdfview.PDFImage.getImage(PDFImage.java:306) at com.sun.pdfview.PDFRenderer.drawImage(PDFRenderer.java:274) at com.sun.pdfview.PDFImageCmd.execute(PDFPage.java:665) at com.sun.pdfview.PDFRenderer.iterate(PDFRenderer.java:577) at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101) at java.lang.Thread.run(Unknown Source)

代碼:

public class Test { 

public static 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:\\testeImpressora\\Print\\pdf\\tutorial.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(String[] args) { 
    SwingUtilities.invokeLater(new Runnable() { 
      public void run() { 
       try { 
        Test.setup(); 
       } catch (IOException ex) { 
        ex.printStackTrace(); 
       } 
      } 
     }); 

}} 
+0

什麼行發生異常? – elyashiv

+0

看到這個鏈接http://wiki.icesoft.org/display/PDF/Using+the+PDF+Viewer+Component它可能會幫助你 – aoulhent

回答

0

檢查路徑,我用我的電腦路徑相同的代碼,並使用PDFRenderer全-0.9.1罐工作好,我想你應該檢查你的jar文件。

+0

沒有單獨的jar爲-full。它是一個包含與PDFRenderer-0.9.1相同的jar文件的zip文件,它仍然會給出錯誤信息 – user5612655