Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


vaithiyanathan
Pdf Viewer
1 Answer(s)      2 years and 4 months ago
Posted in : Java Beginners


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


Advertisement
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
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
Advertisements
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
TightVNC Java Viewer connection
TightVNC Java Viewer connection  I have source code of the tight VNC and installed 'Real VNC' on my local system. When I run the source of tight VNC, it asked for the host and port so I passed following credentials: Host
Filter Implementation In flexible hierarchy Tree Viewer
Filter Implementation In flexible hierarchy Tree Viewer    I am implementing a tree viewer using flexible hierarchy Tree Viewer. I followed the DSF examples and could successfully implement the tree viewer. Now, I want
Filter Implementation In flexible hierarchy Tree Viewer
Filter Implementation In flexible hierarchy Tree Viewer    I am implementing a tree viewer using flexible hierarchy Tree Viewer. I followed the DSF examples and could successfully implement the tree viewer. Now, I want
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
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
The Java Applet Viewer
The Java Applet Viewer       Applet viewer is a command line program to run Java applets.... The other way to run an applet is through Java applet viewer. This is a tool
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
Setting Applet Viewer Properties - Java Beginners
Setting Applet Viewer Properties  Hi, I'm developing an applet using netbeans 6.1 ide. I want to set the appletviewer's width and height so I can test the applet from the ide and not from the browser through a html page. How
The Java Applet Viewer
The Java Applet Viewer       Applet viewer is a command line program to run Java applets.... The other way to run an applet is through Java applet viewer. This is a tool
PDF to Image
PDF to Image  Java code to convert PDF to Image
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 to text
pdf to text  how to covert pdf file (which contain table and text) into word or excel file using itext api
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
PDF document
PDF document  hello, How to Open a PDF document on iPhone??   You can use these There's a whole toolkit built in which lets you render PDF pages to a UIView. Check out: CGPDFDocumentCreateWithURL
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
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
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
Write to PDF
Write to PDF  Hi, Fairly new to this. I want to create a PDF file as a server call, with text/images sent to the app. Seeing that this will have to be a plugin, how do I go about making it a valid plugin for the server
how to load pdf on html
how to load pdf on html  how to load pdf on html
Download PDF file
Download PDF file  How to download PDF file with JSF
open pdf in uiwebview
open pdf in uiwebview  Hi, How to open pdf in uiwebview? Thanks
Creating PDF in JAVA
Creating PDF in JAVA  How create pdf in java ? Take value from database for particular PDF
pdf to voice converter
pdf to voice converter  is it possible to implement PDF to speech converter by extracting text from pdf and then text to speech
PDF Generation for unicode characters
PDF Generation for unicode characters  Hi, How a PDF file having unicode characters is generated in JSP
pdf format - JSP-Servlet
pdf format  hi Sir, how to convert text format into PDF format. thanks & regards, vijayababu.m
download pdf files
download pdf files  pls help me,I don't know how to convert .doc,.docx files into pdf files and download that pdf files using servlet or jsp
pdf generate from jsp
pdf generate from jsp  how do i generate a pdf using jsp that should query the data from the database and write it into a pdf and download the same
generate pdf in spring
generate pdf in spring  HOw do i generate pdf in a spring application, so that my click should query the database and a pdf should be generated and downloaded to the client side
generate pdf using jsp
generate pdf using jsp  how do i generate a pdf using jsp that should query the data from the database and write it into a pdf and download the same
create pdf from jsongrid
create pdf from jsongrid  i need to create pdf from jsongrid in java struts2.. otherwise i need to create pdf from result set
generate pdf in spring
generate pdf in spring  HOw do i generate pdf in a spring application, so that my click should query the database and a pdf should be generated and downloaded to the client side
pdf file in jsp
pdf file in jsp  i have a pdf, which has to be displayed in a jsp page along with some html tags, the pdf which is to be displayed shold be readonly and wont allow the uer to save too
convert excel into pdf
convert excel into pdf  How to convert excel into pdf files
about pdf file handeling
about pdf file handeling  can i apend something in pdf file using... to handle pdf files. You can find the related examples from the given link: Handling PDF files
Generating pdf in Spring
Generating pdf in Spring  Sir/Madam, I need your help in generating a pdf by fetching the data form database and by using unicode in spring framework
Converting PDF in to XML
Converting PDF in to XML  I have to convert PDF into XMl without any loss in text. Please suggest sth good
Reports to pdf conversion
Reports to pdf conversion  I need to convert reports into pdf format using java.. Will i get any sample code
Extarct string from PDF
Extarct string from PDF  how can i search a particular character from pdf? also extarct string from a pdf document
pdf to xml conversion
pdf to xml conversion  i want to convert pdf file into xml file.. where i am having a table in pdf file with some headers and some data into it. i want the headers to be the tag of xml file. how can i do that using java? please
Direct Access of PDF
Direct Access of PDF  Hi During the security audit of my project ,i got an case in report dat is no one can access the pdf file without login.I have no's of pdf in a folder,but problem is this any1 can open the pdf by knowing
about pdf file handeling
about pdf file handeling  i have downloaded a jar file containing packages for writing in pdf files . in which folder i should copy it ? i'm using windowsXP os.pls give whole path
pdf editor for iphone
pdf editor for iphone  hi i wanted help in creating a pdf editor for iphone. what are the steps needed to follow to develop the same? any help in this regard .. thanks
PDF reader in android - JavaMail
PDF reader in android  Hi, iam trying to open and perform basic operations on PDF file in android. But i unable to get it. IS there any possibilities to solve that problem? Waiting for reply
iPhone PDF UIWebview
iPhone PDF UIWebview  In my iPhone application i am trying to load the pdf file on UIWebview.. but some how it's not working. Please suggest. Code...] pathForResource:@"test" ofType:@"pdf"]; NSData* data = [NSData
Adding images in itext pdf
Adding images in itext pdf  Hi, How to add image in pdf file using itext? Thanks   Hi, You can use following code... image in the pdf file. Thanks
Creating files of PDF's thumnails
Creating files of PDF's thumnails  Hi, How to create PDF's thumbnail in PHP? Thanks   Hi, You should have ImageMagick support on your server. You can then use following code to create PDF thumbnail image. <?php
Advertisements
 

 

 

DMCA.com