Learning The "J"

Home » JAVA Learning » Working with PDF » Reading PDF

Category Archives: Reading PDF

Reading PDF files

Reading PDF Files

import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfTextExtractor;
import java.io.FileWriter;
import java.io.IOException;

public class ReadingPDF {

    public static void main(String ar[]) {
        try {
            PdfReader readerN = new PdfReader("c:\\anchor.pdf");
            for (int i = 1; i <= 1; i++) {
                String myLine = PdfTextExtractor.getTextFromPage(readerN, i);
                System.out.println(myLine);

                try {
                    FileWriter fw = new FileWriter("c://reading.txt", true);
                    fw.write(myLine);
                    fw.close();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
Advertisements