Created
August 25, 2011 07:18
-
-
Save krmahadevan/1170150 to your computer and use it in GitHub Desktop.
This sample program helps you work with a pdf file over the net and extract its contents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedInputStream; | |
import java.io.IOException; | |
import java.net.URISyntaxException; | |
import java.net.URL; | |
import org.apache.pdfbox.pdfparser.PDFParser; | |
import org.apache.pdfbox.util.PDFTextStripper; | |
public class PlayWithPDF { | |
/** | |
* @param args | |
* @throws URISyntaxException | |
* @throws IOException | |
*/ | |
public static void main(String[] args) throws URISyntaxException, IOException { | |
URL url = new URL("http://illiad.evms.edu/sample.pdf"); | |
System.out.println(getTextFromPDF(url)); | |
} | |
public static String getTextFromPDF(URL url) throws IOException{ | |
BufferedInputStream fileToParse = new BufferedInputStream(url.openStream()); | |
PDFParser parser = new PDFParser(fileToParse); | |
parser.parse(); | |
String text = new PDFTextStripper().getText(parser.getPDDocument()); | |
System.out.println(text); | |
parser.getPDDocument().close(); | |
return text; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make sure that the following is added up as a Maven dependency for this to work.