0% found this document useful (0 votes)
41 views2 pages

Programe For Fioe Convert

This document discusses how to convert a PDF file to text file in Java. It uses the iText API to read a sample resume.pdf file using the PDFReader class. The data is converted to bytes then to a string using a StringBuffer, and written to a new pdf.txt file. The code provided opens the PDF, gets the content stream, tokenizes it, appends any string tokens to a buffer, and writes the resulting string to the text file.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views2 pages

Programe For Fioe Convert

This document discusses how to convert a PDF file to text file in Java. It uses the iText API to read a sample resume.pdf file using the PDFReader class. The data is converted to bytes then to a string using a StringBuffer, and written to a new pdf.txt file. The code provided opens the PDF, gets the content stream, tokenizes it, appends any string tokens to a buffer, and writes the resulting string to the text file.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

In this section, you will learn how to convert pdf file to text file using Java Programming.

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. The data is first converted into bytes and then with the use of StringBuffer, it will again converted into string and write into the pdf.txt file 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) {} } }

You might also like