Announcement Announcement Module
Collapse
No announcement yet.
How to Create a PDF File Reader Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to Create a PDF File Reader

    Since the PDF (Postscript Document Format) was approved as an International Standard Organization (ISO) recommendation by the W3C in 2008, the availability of open-source and commercial software applications for PDF file format manipulation and viewing has significantly expanded. PDF formatted files are popular throughout the industry because of their ability to be viewed across varying computing platforms and difficulty in modifying the file format. Java is a popular programming language to create PDF file readers using open-source and commercially available libraries with the latest Java Sun Developer Kit. JPedel is an example of a dual-purpose PDF Java library (Open-Source and Commercial Implementations) that can be used to create a PDF File reader.
    1.
    1

    Download and install the latest Java Software Developer's Kit listed in Resources.
    2.
    2

    Open a new Java class in your text editor or Java development application and include the required Java AWT and Javax Swing Class's for creating a Graphical User Interface (UI).
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowListener;

    import javax.swing.JFrame;
    import javax.swing.JInternalFrame;
    import javax.swing.JLabel;
    3.
    3

    Import the Commands and SimpleViewer classes from the JPedal library after the Swing and AWT Class imports.
    import org.jpedal.examples.simpleviewer.Commands;
    import org.jpedal.examples.simpleviewer.SimpleViewer;
    4.
    4

    Create a JFrame and JInternal Frame in Java Swing to view the PDF File.
    public class myPDFViewer
    {

    public static void main(String[] args)
    {
    //The Primary Frame to host the PDF File
    JFrame myPDFFrame = new JFrame();
    myPDFFrame.getContentPane().setLayout(new BorderLayout());

    //The Primary Internal Frame that will display the PDF File within the JFrame
    JInternalFrame pdfContainer = new JInternalFrame("My PDF Viewer");

    //Labels the PDF Viewer
    JLabel label = new JLabel("My PDF Viewer");
    label.setFont(new Font("Lucida", Font.BOLD, 22));
    label.setForeground(Color.Black);
    frame.add(label, BorderLayout.NORTH);
    5.
    5

    Create a SimpleViewer Class, myPDFViewer to render the PDF Document in the JInternal frame. Following the SimpleViewer Class instantiation, complete the JFrame setup by configuring the frame title, size and WindowListener handlers.
    SimpleViewer myPDFViewer = new SimpleViewer(pdfContainer, null);
    myPDFFrame.add(pdfContainer, BorderLayout.CENTER);

    pdfContainer.setVisible(true);

    //Set up JFrame
    myPDFFrame.setTitle("PDF Viewer in Java");
    myPDFFrame.setSize(850, 650);
    myPDFFrame.addWindowListener(new WindowListener(){
    public void windowActivated(WindowEvent e) {}
    public void windowClosed(WindowEvent e) {}
    public void windowClosing(WindowEvent e) {System.exit(1);}
    public void windowDeactivated(WindowEvent e) {}
    public void windowDeiconified(WindowEvent e) {}
    public void windowIconified(WindowEvent e) {}
    public void windowOpened(WindowEvent e) {}
    });

    //Display the PDF Viewer
    frame.setVisible(true);
    6.
    6

    Pass the filepath for the test PDF file to the PDF File handler as an array of Objects and view the PDF File in the JFrame.
    Object[] myPDFinput;

    //Specify file you wish to open (JPedal handles getting the byte data)
    myPDFinput = new Object[]{"/Test/mytest.pdf"};
    myPDFViewer.executeCommand(Commands.OPENFILE, input);

    } // end Main

    } //end Class
    7.
    7

    Compile and run the java program to view myPDFViewer loading the test PDF file.

  • #2
    Since the PDF (Postscript Document Format) was approved as an International Standard Organization (ISO) recommendation by the W3C in 2008, the availability of open-source and commercial software applications for PDF file format manipulation and viewing has significantly expanded. PDF formatted files are popular throughout the industry because of their ability to be viewed across varying computing platforms and difficulty in modifying the file format. Java is a popular programming language to create PDF file readers using open-source and commercially available libraries with the latest Java Sun Developer Kit. JPedel is an example of a dual-purpose PDF Java library (Open-Source and Commercial Implementations) that can be used to create a PDF File reader.

    ______________________________

    For Searching whatever you like click here

    Comment


    • #3
      But for someone who want to creat PDF reader in C#,this page definitely can be helpful.

      Comment

      Working...
      X