Simple java swing application to view PDF file using java PDF Renderer library:
public class Main {
public static void setup() throws IOException {
PagePanel panel = new PagePanel();
this.add(panel);
this.pack();
this.setVisible(true);
//load a pdf from a byte buffer
Path currentRelativePath = Paths.get("");
String s = currentRelativePath.toAbsolutePath().toString();
File file = new File(s+"/pdf/test.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 staic void main(String args[]){
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
Main.setup();
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
}
}