public static void main(String[] args) throws Exception {
if( args.length != 1 )
{
usage();
}
else
{
PDDocument document = null;
try
{
document = PDDocument.load( args[0] );
if( document.isEncrypted() )
{
try
{
document.decrypt( "" );
}
catch( InvalidPasswordException e )
{
System.err.println( "Error: Document is encrypted with a password." );
System.exit( 1 );
}
}
PrintTextLocations printer = new PrintTextLocations();
List allPages = document.getDocumentCatalog().getAllPages();
for( int i=0; i< allPages.size(); i++ )
{
PDPage page = (PDPage)allPages.get( i );
System.out.println( "Processing page: " + i );
PDStream contents = page.getContents();
if( contents != null )
{
printer.processStream( page, page.findResources(), page.getContents().getStream() );
}
}
}
finally
{
if( document != null )
{
document.close();
}
}
}
}
This will print the documents data. |