martedì 11 novembre 2008

PDFBox is the solution

public static void main( String[] args ) throws Exception{
Writer output = null;
PDDocument document = null;
File f = new File("prova.txt");
System.out.println("1) Last: "+f.lastModified());
String pdfFile = "ChapterSection.pdf";
try {
document = PDDocument.load( pdfFile );
output = new OutputStreamWriter(new FileOutputStream( "prova.txt" ) );
//output = new OutputStreamWriter( System.out );
PDFTextStripper stripper = new PDFTextStripper();
stripper.setSortByPosition(true);
stripper.setStartPage( 1 );
stripper.setEndPage( document.getNumberOfPages() );
stripper.writeText( document, output );
finally{
if( output != null ){
output.close();
}
if( document != null ){
document.close();
}
}
System.out.println("2) Last: "+f.lastModified());
}

Nessun commento: