textFile = pdfFile.substring( 0, pdfFile.length() -4 ) + ".txt";
}
InputStream input = null;
Writer output = null;
COSDocument document = null;
try
{
input = new FileInputStream( pdfFile );
long start = System.currentTimeMillis();
document = parseDocument( input );
long stop = System.currentTimeMillis();
LOG.info( "Time to parse time=" + (stop-start) );
//document.print();
if( document.isEncrypted() )
{
try
{
DecryptDocument decryptor = new DecryptDocument( document );
decryptor.decryptDocument( password );
}
catch( InvalidPasswordException e )
{
if( args.length == 4 )//they supplied the wrong password
{
System.err.println( "Error: The supplied password is incorrect." );
System.exit( 2 );
}
else
{
//they didn't suppply a password and the default of "" was wrong.
System.err.println( "Error: The document is encrypted." );
usage();
}
}
}
if( toConsole )
{
output = new OutputStreamWriter( System.out );
}
else
{
output = new OutputStreamWriter(
new FileOutputStream( textFile ), encoding );
}
start = System.currentTimeMillis();
stripper.writeText( document, output );
stop = System.currentTimeMillis();
LOG.info( "Time to extract text time=" +(stop-start) );
}
finally
{
if( input != null )
{
input.close();
}
if( output != null )
{
output.close();
}
if( document != null )
{
document.close();
}
}
}