Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package edu.umsl; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.PrintWriter; import java.util.Scanner; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.text.PDFTextStripper; /** * * @author njc3n3 */ public class runPDF { File pdfFile; File txtFile; String content; Scanner sc = new Scanner(System.in); public static void main(String[] args) throws IOException { runPDF myPDF = new runPDF(); myPDF.readPDF(); myPDF.writeText(); } public void readPDF() throws IOException { System.out.println("Please enter PDF file location, omit extension: "); String input = sc.next(); pdfFile = new File(input); PDDocument pdDocument = PDDocument.load(pdfFile); PDFTextStripper strip = new PDFTextStripper(); // strip.setStartPage(1); // strip.setEndPage(1); content = strip.getText(pdDocument); System.out.println("PDF Read"); // System.out.println(content); // FileOutputStream outStream; // strip.writeText(txtFile, outStream); } public void writeText() throws FileNotFoundException, IOException { System.out.println("Please enter TXT file location, omit extension: "); String input = sc.next(); txtFile = new File(input); FileOutputStream FOS = new FileOutputStream(txtFile); ObjectOutputStream OOS = new ObjectOutputStream(FOS); OOS.writeObject(content); OOS.flush(); OOS.close(); FOS.flush(); FOS.close(); System.out.println("Text File Written"); // PrintWriter pw = new PrintWriter(txtFile); // pw.write(content); } }