Project PDF-Renderer
Monday Jun 16, 2008
Today I have raised the observer permission for project PDF-Renderer. Awesome project which help Java Developer to work on PDF format. A complete viewer and render. API's are strong and I have just check this code from site itself. This code put the first page of your PDF file inside PagePanel. No doubt PDF is one of the open format used worldwide across all OS. In such a case, support from Java is something like adding more flavor in sweet.
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;
import com.sun.pdfview.PagePanel;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import javax.swing.*;
/**
* An example of using the PagePanel class to show PDFs. For more advanced
* usage including navigation and zooming, look ad the
* com.sun.pdfview.PDFViewer class.
*
* -AT-author joshua.marinacci@sun-DOT-com
*/
public class Main {
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("Amityform.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 {⁞
Main.setup();
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
}
}
Just download the jar file from project site. And then :
javac -cp PDFRenderer.jar Main.java
java -cp PDFRenderer.jar;. Main
It is pretty fast as well, because IO operation has been done by NIO and channels are superb. Thanks guys for making such a great project.















Hi, I downloaded pdfview sourcecode manually ...
Oh, page pane...
PDF Renderer jar files are working for some file ,...
This is what developer of this project told me -
...I am not able to find library of com.sun.pdfview.*
I am not able to find library of com.sun.pdfview.P...
Yes Tapasya ! There are some issues with the curre...