document reading in java

document reading in java

Hi Dipak,
Can you tell me how to read pdf files in to java.i want convert pdf file in xml format through java coding.can you please help me?
View Answers

May 12, 2010 at 4:23 PM

Hi Friend,

Try the following code:

import java.io.*;
import java.util.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

public class ReadPDF {
public static void main(String[] args) throws IOException {
try {
Document document = new Document();
document.open();
PdfReader reader = new PdfReader("file.pdf");
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());
}
}
String test=buffer.toString();
System.out.println(test);
}
catch (Exception e) {}
}
}

For the above code,you need itext-2.0.6.jar.

Thanks









Related Tutorials/Questions & Answers:
document reading in java - Java Beginners
document reading in java  Hi Dipak, Can you tell me how to read pdf files in to java.i want convert pdf file in xml format through java...(String[] args) throws IOException { try { Document document = new
word document reading - Development process
word document reading  I am in the midst of reading a word document while reading charts(EMF or WMF) pictures i am not able to do so can u suggest one class for this to accomplish
Advertisements
Reading a text file in java
in java.io.* package for reading and writing to a file in Java. To learn more about reading text file in Java see the tutorial Read File in Java. Thanks...Reading a text file in java  What is the code for Reading a text file
Reading files in Java
. Please provide me the example code for reading big text file in Java. What do you suggest for Reading files in Java? Thanks...Reading files in Java  I have to make a program in my project
Reading big file in Java
Reading big file in Java  How to read a big text file in Java program?   Hi, Read the complete tutorial at How to read big file line by line in java? Thanks
Best way to reading file in java
Best way to reading file in java  Hi, As a beginner I want to learn about Java programming and make a program for reading a text file in java. What is the best way for reading file in Java? Thanks
reading excel sheet in java
reading excel sheet in java  can anyone tell me a proper java code to read excel sheet using poi   Here is a java code that reads an excel file using POI api and display the data on the console. import java.io.
web page reading in java
web page reading in java  i wanna read webpage in that i want to get the data from the particular tags like (,) and store into the data base...... can any body tell me the solution? plz urgnt. thanks and regards, jasti  
xml file reading using java
xml file reading using java  hi deepak I want to read some data from xml file and send that output to particular email address using java  ...(); Document doc = docBuilder.parse("roseindia.xml"); Element element
Reading an XML document using JDOM
Reading an XML document using JDOM   ..., it is a tree based Java api. JDOM represents an XML document as a tree composed... are some of the methods used in code given below for reading an XML document
reading from pdf to java - Java Beginners
reading from pdf to java  How can i read the pdf file to strings in java. I need the methods of reading data from file and to place that data in the string, using java.   Hi Friend, We are providing you a code
Reading and Writing files - Java Beginners
Reading and Writing files  Hello, please help me to Develop a simple Java application that, when run, Welcomes the users and tells them the name of the last person to run the application, this information should be retrieved
problem in reading 10000 records in java
problem in reading 10000 records in java  Hi I have a huge records 10000 records ,while reading it show some error only i can able to read 2000 recds and need to display all the recods in jsper reports Thanks Gopi
Reading Files and Print - Java Beginners
Reading Files and Print  Hey Guys, I'm a beginner to java and I wanna write this program. I wanna create files including information of the students in my class. Each file contains a student's name, e-mail, school, hobby
Reading a file from Jar JAVA
Reading a file from Jar JAVA  I have added one excel sheet into a jar file. can anybody tell me how i can read that file. actually when i am running code from eclipse i able to read it but when i am adding that jar file
Reading a file from Jar JAVA
Reading a file from Jar JAVA  I have added one excel sheet into a jar file. can anybody tell me how i can read that file. actually when i am running code from eclipse i able to read it but when i am adding that jar file
Reading RDF file using Java code in Eclipse
Reading RDF file using Java code in Eclipse  Could you please tel me what this statement means - Model model = ModelFactory.createDefaultModel
Java program for printing document
Java program for printing document  can u send me the java program for printing the office document? email: [email protected]
reading and displaying svg file through java
reading and displaying svg file through java  sample program for reading a svg file
Reading text from image file - Java Beginners
Reading text from image file  How Read text from image file
Java example for Reading file into byte array
Java example for Reading file into byte array. You can then process the byte... in Java for reading file into byte array. Sometimes it becomes necessary... of reading file into byte array: Java file to byte array
reading data using struts and jsp java
reading data using struts and jsp java  how can i read data entered by user into a textbox (jsp page) into struts action class ex emp id,so that after reading emp_id it can be read into struts action class for retrieving other
Writing to and reading from a binary file in java.
Writing to and reading from a binary file in java.  I have written the following code to convert an ASCII text file to a binary file: public static... work, but the records obtained after reading the binary file are much less than
initialise array by reading from file - Java Beginners
initialise array by reading from file  Hello, I wnat to know how i would initialise an array by reading a text file, which contains a simple pattern. for example the file may look as shown below, with the star character
Video Tutorial of reading file in Java
get the source code of reading a text file in Java. This source code can... tutorials of reading files in Java How To Read... Java example for Reading file into byte array Learn how
Creating MS Word document in java - Struts
Creating MS Word document in java  I have one template in MS Word... content and also i need to set header and footer in doc file. That is, reading... you plz tell me how to do in java
Reading binary file into byte array in Java
Example code of reading binary file into byte array in Java This example shows you how to read a binary file into byte array from Java program. This type... is the complete code of the Java program that reads the binary file into byte array:ADS
Java error reading from file
Java error reading from file       Java error reading file are the common error occurred  in java that when the user encounter a corrupt file
How to merge two word document using java
How to merge two word document using java   how to merge two word document using java
How to merge two word document using java
How to merge two word document using java   how to merge two word document using java
reading from pdf
reading from pdf  how can i read specific words from pdf file?   Java Read pdf file import java.io.*; import java.util.*; import... { Document document = new Document(); document.open
Create Bar Graph from reading excel sheet in Java
Create Bar Graph from reading excel sheet in Java  I'm New to Java and I have to create a java program where I have to read data from multiple excel sheets say 4 sheets and sheet represents browsers (like FF, IE8, IE9 , chrome
java code to open and display MS-word document
java code to open and display MS-word document  java code to open and display MS-word document
export to word document - Java Beginners
export to word document  hi sir,when i am click on a button under the jtable,for example (print button),then i want to print that jtable in word document,automatically,plz provide program sir  Hi Friend, Try
Err while reading CSV file using POI - Java Beginners
Err while reading CSV file using POI  Hi, When i am trying to read a CSV file using POI Dile system, the below error is coming up. java.io.IOException: Invalid header signature; read 2334956330951926093, expected
How to make a design document for exception handling in java
How to make a design document for exception handling in java  How to make a design document for exception handling
Reading xml file using dom parser in java with out using getelementby tag name
Reading xml file using dom parser in java with out using getelementby tag name  Hi, How to read the xml file using java with dom parser, but without... found some thing in the below url : http://www.roseindia.net/answers/viewqa/Java
Reading the data from property file from java stand alone application in linux
Reading the data from property file from java stand alone application in linux  Please send me the example of reading the data from a property file from java stand alone application in linux. I don't know how to give path
open document
open document  open a word document using jsp   Please go through the following link: Java Read word document file The above link will provide an example that will read the document file using POI library in java
svg file reading and display
svg file reading and display  i want a sample program for reading and displaying the content of a svg file
Question about parsing XML document with DOM in JAVA.
Question about parsing XML document with DOM in JAVA.  Hi, I need to parse a XML file witch has info about classes. So i have for each class to have its methods and for each method to get its parameters. I'm trying to do
Java Servlet : Reading Form Data Example
Java Servlet : Reading Form Data Example In this tutorial, we are discussing about reading form data of a servlet. Reading Form Data : There are three methods of servlet to handle the form data. These are listed below -ADS
java code to create xml document from DOM object
java code to create xml document from DOM object  Hey! After knowing the way we can create DOM objects and add elements to it-> then displaying it on the console ;is there a way I can output the same in xml document
Using poi hwpf,how to create table in word document. - Java Beginners
Using poi hwpf,how to create table in word document.  Can you please tell me how to create a table in the word document in java using Apache poi hwpf.its very urgent.Please send some sample code.Thanks in advance
Reading a big file effeciently
Reading a big file effeciently  How to read a large text file quickly without memory error in Java? What is the best method to read a big file very efficiently? Thanks   Hi, Kindly check the program Java Read File
Thread for reading txt file
Thread for reading txt file  how to use 3 thread to read 3 txt file? To create three threads for reading the file and three threads for getting the strings out of the queue and printing them. thanks
Reading .doc file using swing
Reading .doc file using swing  Sir, Could U Please Tell me the Way To Read .doc file in java using swing,with code
file reading - Swing AWT
of doc or exe file except for txt file in java.   Hi Friend, Use...(file.getAbsolutePath()); HWPFDocument document=new HWPFDocument(fis); extractor = new WordExtractor(document); String [] fileData = extractor.getParagraphText
Reading file into bytearrayoutputstream
input stream and byte output stream. This is and good example of reading file... In this example we have used the class InputStream for reading the file... import java.io.*; /** * Example of Reading file into byte array
How to set iText pdf document background image - Java Beginners
How to set iText pdf document background image  Hi, I have created the pdf document using the iText classes. but i need to set the background image for this pdf document. there is way to set the background color, but i

Ads