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



Home Answers Viewqa XML Convert pdf to rtf and txt
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Nidhi Kapoor
Convert pdf to rtf and txt
1 Answer(s)      5 years and 3 months ago
Posted in : XML



Advertisement
View Answers

October 9, 2009 at 3:33 PM


Hi Friend,

Try the following codes:

1)Convert PDF to RTF
import java.io.*;
import java.util.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

public class ConvertPDFToRTF {
public static void main(String[] args) throws IOException {
try {
Document document = new Document();
document.open();
PdfReader reader = new PdfReader("C:\\resume.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);
FileOutputStream fos=new FileOutputStream("resume.rtf");
StringBuffer buffer = new StringBuffer();
while (tokenizer.nextToken()) {
if (tokenizer.getTokenType() == PRTokeniser.TK_STRING) {
buffer.append(tokenizer.getStringValue());
}
}
String test=buffer.toString();
StringReader stReader = new StringReader(test);
int t;
while((t=stReader.read())>0)
fos.write(t);
document.close();
System.out.println("Converted Successfully");
}
catch (Exception e) {}
}
}

2)Convert PDF to TEXT
import java.io.*;
import java.util.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

public class ConvertPDFToTEXT {
public static void main(String[] args) throws IOException {
try {
Document document = new Document();
document.open();
PdfReader reader = new PdfReader("C:\\resume.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);
FileOutputStream fos=new FileOutputStream("pdf.txt");
StringBuffer buffer = new StringBuffer();
while (tokenizer.nextToken()) {
if (tokenizer.getTokenType() == PRTokeniser.TK_STRING) {
buffer.append(tokenizer.getStringValue());
}
}
String test=buffer.toString();
StringReader stReader = new StringReader(test);
int t;
while((t=stReader.read())>0)
fos.write(t);
document.add(new Paragraph(".."));
document.close();
}
catch (Exception e) {}
}
}
Thanks


Related Tutorials/Questions & Answers:
Convert pdf to rtf and txt - XML
Convert pdf to rtf and txt  Can we convert PDF to RTF and TXT, and how?  Hi Friend, Try the following codes: 1)Convert PDF to RTF...) {} } } 2)Convert PDF to TEXT import java.io.*; import java.util.
How to Convert PDF into rtf File Java
How to Convert PDF into rtf File Java  Hi, How could in covert the PDF file to rtf file in Java Programming. Please suggest any online example... the online example of Java Convert PDF into rtf File. Thanks
Advertisements
Convert pdf to rtf file using Java
Convert pdf to rtf file using Java In this section, you will learn how to convert .pdf file to .rtf file in java programming language. We have used itext api for this purpose. To read resume.pdf  file, we have used PDFReader class
Uploading and download pdf or .txt file.
Uploading and download pdf or .txt file.  I want admin user to upload pdf file into database and the users can download those pdf format from database
rtf
created one JSP(used pre defined javascript in jsp to get rtf format in browser) which creats RTF Format in browser to enter data. MY question is after i...); //convert all types of single quotes /*tmpString = tmpString.replace((char
convert excel into pdf
convert excel into pdf  How to convert excel into pdf files
'Hello World' file from a servlet (PDF, HTML or RTF).
 'Hello World' file from a servlet (PDF, HTML or RTF...; In this program we are going to tell you how we can create three file rtf,pdf and html files.And we are printing here Hello Word on PDF, HTML, And RTF formate
convert .txt file in .csv format - Java Beginners
convert .txt file in .csv format  Dear all, I hope you are doing good. I am looking to convert .txt file in .csv format. The contents might have different names and values. e.g. start: id:XXXX name:abc address:xyz
convert data from pdf to text file - Java Beginners
convert data from pdf to text file   how to read the data from pdf file and put it into text file(.txt
convert word document to pdf
convert word document to pdf  Hi, Could you please help me write a java code that converts the word docuemnt into PDF? I have to save the generated..."); f.convert(fos,"pdf"); I would also want to know, what does "OfficeFile" in the code
convert an pdf file to html in Java
convert an pdf file to html in Java  Hi all, How to convert an pdf file to html in Java? Currently all my data is generated into a report in pdf and i want to be able to generate it to html page as well. How to go about
Convert BLOB to PDF and save it to a location
Convert BLOB to PDF and save it to a location  I have a requirement to convert blob(stored in a DB table) back to .pdf in the UI(for the users... it has to convert each blob to a pdf and zip it, which the user should be able
How to convert a swing form to PDF
How to convert a swing form to PDF  Sir, I want to know about how convert a swing form containing textbox,JTable,JPanel,JLabel, Seperator etc swing menus to a PDF file using java code
Java code to convert pdf file to word file
Java code to convert pdf file to word file  How to convert pdf file to word file using Java
Convert Text File to PDF file
Convert Text File to PDF file  Here is the way how to covert your Text file to PDF File, public class TextFileToPDF { private static void...(inLine); System.out.println("Text is inserted into pdf file
Convert Text File to PDF file
Convert Text File to PDF file  import java.io.BufferedReader; import java.io.FileOutputStream; import java.io.FileReader; import...); System.out.println("Text is inserted into pdf file"); document.close
CONVERT JTable DATA TO PDF FILE
CONVERT JTable DATA TO PDF FILE  HOW TO CONVERT JTable DATA TO .PDF... the jtable data from the jframe and stored the data into the pdf file in the form...); button=new JButton("Save to pdf"); button.addActionListener(new ActionListener
to convert html to pdf in java - Java Beginners
to convert html to pdf in java  HI all, i want to convert html to pdf using java. actually i dont need as the tags in the html. but the tags should be removed and i need only the text in that. Thanks in advance
To convert Html to pdf in java - Java Beginners
To convert Html to pdf in java  Hi all, I want to convert html file to pdf file using java. can any one help me out. Thanks & Regards Santhosh Ejanthkar  Hi Friend, Try the following code: import
Convert PDF to XML in Java
Convert PDF to XML File in Java In this Java tutorial section, you will learn how to convert pdf file to xml using java program. We have used itext api for this purpose. To read hello.pdf file, we have used PDFReader class. The data
Java convert jtable data to pdf file
Java convert jtable data to pdf file In this tutorial, you will learn how to convert jtable data to pdf file. Here is an example where we have created... have fetched the data from the jtable and save the data to pdf file. Example
rtf_jsp_javascript
rtf_jsp_javascript  Hi every one plz give me answer for below question ASAP I created one JSP(used pre defined javascript in jsp to get rtf format in browser) which creats RTF Format in browser to enter data. MY question
Convert pdf to text file using Java
How to Convert pdf to text file in Java In this section, you will learn how to convert pdf file to text file in Java Programming. We have used itext api for this purpose. To read resume.pdf  file, we have used PDFReader class
Convert ZIP To PDF
Convert ZIP To PDF       Lets discuss the conversion of a zipped file into pdf file... it and then store it into a byte array. Convert this array of byte into the string
Convert Text To PDF
Convert Text To PDF       Here we are discussing the convertion of a text file into a pdf file... into the add() method of the document class to generate a pdf file. Download iText API
Convesion of txt file to doc file.??????
Convesion of txt file to doc file.??????  how to convert text file to doc file using java
PDF to Image
PDF to Image  Java code to convert PDF to Image
".txt" to sql with JDBC
".txt" to sql with JDBC  how to insert ".txt" into sql result[BLOB] with JDBC
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
txt to cvs format
txt to cvs format  i am writing a simple program that read a text...; /*this program reads files from inpath and writes them to outpath as a single txt...(); } //this class converts the text file into binary static void convert(String to_convert
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. but in rtf format data can view. or can icon save like this to be dissapear
 

 

 

DMCA.com