Pdf Viewer

Pdf Viewer

How to diplay the pdf files in java panel using scrollpane...

View Answers

March 15, 2012 at 5:58 PM

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

class PDFViewer 
{
    public static void main(String[] args) 
    {
        final JFrame f=new JFrame();
        f.setLayout(null);
        JLabel label=new JLabel("Select File");
        final JTextField text=new JTextField(20);
        final JTextArea area=new JTextArea(20,10);
        final JScrollPane pane=new JScrollPane(area);
        JButton b1=new JButton("Browse");
        JButton b2=new JButton("Show Data");

        b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
                JFileChooser fileChooser = new JFileChooser(new File("C:/"));
                fileChooser.addChoosableFileFilter(new MyFilter());

                fileChooser.showOpenDialog(f);
               File f=fileChooser.getSelectedFile();
               String path=f.getPath();
               text.setText(path);

            }
        });

      b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
                File f=new File(text.getText());
                try {
      Document document = new Document();
      document.open();
      PdfReader reader = new PdfReader(f.getPath());
      PdfDictionary dictionary = reader.getPageN(1);
      PRIndirectReference reference = (PRIndirectReference) 
                dictionary.get(PdfName.CONTENTS);
                        PRStream stream = (PRStream) PdfReader.getPdfObject(reference);
                        byte[] bytes = PdfReader.getStreamBytes(stream);
                        PRTokeniser tokenizer = new PRTokeniser(bytes);
                        StringBuffer buffer = new StringBuffer();
                        while (tokenizer.nextToken()) {
                        if (tokenizer.getTokenType() == PRTokeniser.TK_STRING) {
                                        buffer.append(tokenizer.getStringValue());
                                        buffer.append("\n");
                                        }
                        }
                String test=buffer.toString();
                area.append(test);

                document.close();
      }
         catch (Exception ex) {}
         pane.setVisible(true);
         }
        });

        label.setBounds(10,10,100,20);
        text.setBounds(120,10,120,20);
        b1.setBounds(260,10,100,20);
        b2.setBounds(380,10,100,20);

        pane.setBounds(120,40,360,100);
        pane.setVisible(false);


        f.add(label);
        f.add(text);
        f.add(b1);
        f.add(b2);
        f.add(pane);
        f.setVisible(true);
        f.setSize(500,300);
    }
}

class MyFilter extends javax.swing.filechooser.FileFilter {
    public boolean accept(File file) {
        String filename = file.getName();
        return filename.endsWith(".pdf");
    }
    public String getDescription() {
        return "*.pdf";
    }
}

For the above code, you need itext api









Related Tutorials/Questions & Answers:
Pdf Viewer
Pdf Viewer   How to diplay the pdf files in java panel using... = file.getName(); return filename.endsWith(".pdf"); } public String getDescription() { return "*.pdf"; } } For the above code, you
pdf from i report
pdf from i report  I have a problem again with my report, i use I Report to make pdf file. but when the application running in java, pdf can't view.../not viewer in Jasperviewer...., thank you, hendra
Advertisements
PDF to Image
PDF to Image  Java code to convert PDF to Image
pdf marking
pdf marking  Hi i am working on online answer sheet evaluation using jsp. It need pdf marking.drag and drop images onto pdf. please help me regards reshma
pdf marking
pdf marking  Hi i am working on online answer sheet evaluation using jsp. It need pdf marking.drag and drop images onto pdf. please help me regards reshma
pdf to text
pdf to text  how to covert pdf file (which contain table and text) into word or excel file using itext api
pdf generation.
pdf generation.  i want to generate the data which is stored in mysql data base in pdf format with php. how i will do
PDF document
PDF document  hello, How to Open a PDF document on iPhone??   You can use theseADS_TO_REPLACE_1 There's a whole toolkit built in which lets you render PDF pages to a UIView. Check out: CGPDFDocumentCreateWithURL
pdf to database
pdf to database  Hi, I want to read the data from pdf(pdf file is having 50 fields) which is placed in database file and store that into MySQL database. I want this process untill the rows completed in the database file
upload pdf
upload pdf   i want to dispal content of pdf fil and stored into database in human readable form using php . how can i do
PDF Comparator
PDF Comparator  Hi Guys, I need to develop a program which should compare a set of pdf files stored in one folder with a set of pdf files stored in another folder. Both folders should contain the same no. of pdf files with same
The Java Applet Viewer
The Java Applet Viewer       Applet viewer is a command line program to run Java applets... viewer. This is a tool that acts as a test bed for Java applets. The working
pdf restriction
pdf restriction  i have certain pdf files that have restrictions on it as copy ,read,extract text etc.. i want to remove restriction by java code. so is there any way to do this? plz help thanks in advance rohit
itext pdf
itext pdf  i am generating pdf using java i want to do alignment in pdf using java but i found mostly left and right alignment in a row. i want to divide single row in 4 parts then how can i do
Version of com.groupdocs>groupdocs-viewer dependency
List of Version of com.groupdocs>groupdocs-viewer dependency
Version of com.klinkerapps>article_viewer dependency
List of Version of com.klinkerapps>article_viewer dependency
DB Schema Viewer
DB Schema Viewer       DB Schema Viewer is an Eclipse plugin that builds a graphical view of an existing database. Reverse Engineering is performed through JDBC
ModuleNotFoundError: No module named 'adr-viewer'
ModuleNotFoundError: No module named 'adr-viewer'  Hi, My Python... 'adr-viewer' How to remove the ModuleNotFoundError: No module named 'adr-viewer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'altair-viewer'
ModuleNotFoundError: No module named 'altair-viewer'  Hi, My... 'altair-viewer' How to remove the ModuleNotFoundError: No module named 'altair-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'altair-viewer'
ModuleNotFoundError: No module named 'altair-viewer'  Hi, My... 'altair-viewer' How to remove the ModuleNotFoundError: No module named 'altair-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'am-viewer'
ModuleNotFoundError: No module named 'am-viewer'  Hi, My Python...-viewer' How to remove the ModuleNotFoundError: No module named 'am-viewer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'am-viewer'
ModuleNotFoundError: No module named 'am-viewer'  Hi, My Python...-viewer' How to remove the ModuleNotFoundError: No module named 'am-viewer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'am-viewer'
ModuleNotFoundError: No module named 'am-viewer'  Hi, My Python...-viewer' How to remove the ModuleNotFoundError: No module named 'am-viewer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'currency-viewer'
ModuleNotFoundError: No module named 'currency-viewer'  Hi, My... named 'currency-viewer' How to remove the ModuleNotFoundError: No module named 'currency-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'currency-viewer'
ModuleNotFoundError: No module named 'currency-viewer'  Hi, My... named 'currency-viewer' How to remove the ModuleNotFoundError: No module named 'currency-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'fits-viewer'
ModuleNotFoundError: No module named 'fits-viewer'  Hi, My Python... 'fits-viewer' How to remove the ModuleNotFoundError: No module named 'fits-viewer' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'giotto-viewer'
ModuleNotFoundError: No module named 'giotto-viewer'  Hi, My... 'giotto-viewer' How to remove the ModuleNotFoundError: No module named 'giotto-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'layer-viewer'
ModuleNotFoundError: No module named 'layer-viewer'  Hi, My Python... 'layer-viewer' How to remove the ModuleNotFoundError: No module named 'layer-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'layer-viewer'
ModuleNotFoundError: No module named 'layer-viewer'  Hi, My Python... 'layer-viewer' How to remove the ModuleNotFoundError: No module named 'layer-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'log-viewer'
ModuleNotFoundError: No module named 'log-viewer'  Hi, My Python... 'log-viewer' How to remove the ModuleNotFoundError: No module named 'log-viewer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'loom-viewer'
ModuleNotFoundError: No module named 'loom-viewer'  Hi, My Python... 'loom-viewer' How to remove the ModuleNotFoundError: No module named 'loom-viewer' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'loom-viewer'
ModuleNotFoundError: No module named 'loom-viewer'  Hi, My Python... 'loom-viewer' How to remove the ModuleNotFoundError: No module named 'loom-viewer' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'markdown-viewer'
ModuleNotFoundError: No module named 'markdown-viewer'  Hi, My... named 'markdown-viewer' How to remove the ModuleNotFoundError: No module named 'markdown-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'networkx_viewer'
ModuleNotFoundError: No module named 'networkx_viewer'  Hi, My... named 'networkx_viewer' How to remove the ModuleNotFoundError: No module named 'networkx_viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'notebook-viewer'
ModuleNotFoundError: No module named 'notebook-viewer'  Hi, My... named 'notebook-viewer' How to remove the ModuleNotFoundError: No module named 'notebook-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'nuclei-viewer'
ModuleNotFoundError: No module named 'nuclei-viewer'  Hi, My... 'nuclei-viewer' How to remove the ModuleNotFoundError: No module named 'nuclei-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'nuclei-viewer'
ModuleNotFoundError: No module named 'nuclei-viewer'  Hi, My... 'nuclei-viewer' How to remove the ModuleNotFoundError: No module named 'nuclei-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'openPMD-viewer'
ModuleNotFoundError: No module named 'openPMD-viewer'  Hi, My... named 'openPMD-viewer' How to remove the ModuleNotFoundError: No module named 'openPMD-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pathme-viewer'
ModuleNotFoundError: No module named 'pathme-viewer'  Hi, My... 'pathme-viewer' How to remove the ModuleNotFoundError: No module named 'pathme-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pathme-viewer'
ModuleNotFoundError: No module named 'pathme-viewer'  Hi, My... 'pathme-viewer' How to remove the ModuleNotFoundError: No module named 'pathme-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'profile-viewer'
ModuleNotFoundError: No module named 'profile-viewer'  Hi, My... named 'profile-viewer' How to remove the ModuleNotFoundError: No module named 'profile-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyc-viewer'
ModuleNotFoundError: No module named 'pyc-viewer'  Hi, My Python... 'pyc-viewer' How to remove the ModuleNotFoundError: No module named 'pyc-viewer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'pyc-viewer'
ModuleNotFoundError: No module named 'pyc-viewer'  Hi, My Python... 'pyc-viewer' How to remove the ModuleNotFoundError: No module named 'pyc-viewer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'pyrtt-viewer'
ModuleNotFoundError: No module named 'pyrtt-viewer'  Hi, My Python... 'pyrtt-viewer' How to remove the ModuleNotFoundError: No module named 'pyrtt-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyrtt-viewer'
ModuleNotFoundError: No module named 'pyrtt-viewer'  Hi, My Python... 'pyrtt-viewer' How to remove the ModuleNotFoundError: No module named 'pyrtt-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'quality-viewer'
ModuleNotFoundError: No module named 'quality-viewer'  Hi, My... named 'quality-viewer' How to remove the ModuleNotFoundError: No module named 'quality-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'quality-viewer'
ModuleNotFoundError: No module named 'quality-viewer'  Hi, My... named 'quality-viewer' How to remove the ModuleNotFoundError: No module named 'quality-viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'requests_viewer'
ModuleNotFoundError: No module named 'requests_viewer'  Hi, My... named 'requests_viewer' How to remove the ModuleNotFoundError: No module named 'requests_viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'requests_viewer'
ModuleNotFoundError: No module named 'requests_viewer'  Hi, My... named 'requests_viewer' How to remove the ModuleNotFoundError: No module named 'requests_viewer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'tinydb-viewer'
ModuleNotFoundError: No module named 'tinydb-viewer'  Hi, My... 'tinydb-viewer' How to remove the ModuleNotFoundError: No module named 'tinydb-viewer' error? Thanks   Hi, In your python

Ads