I'm having trouble viewing a page in PagePanel, when trying to display the pdf, error occurs "java.nio.BufferUnderflowException."
Error:
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)
Code:
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();
}
}
});
}}
Check the Path I used the same code on my Pc Path and worked good using PDFRenderer-full-0.9.1 Jar, I think you should check your Jar file.