public static void main ( String [ ] args ) { try { if ( args . length < 1 || args . length > 3 ) { System . out . println ( "Usage: PdfContentReaderTool <pdf file> [<output file>|stdout] [<page num>]" ) ; return ; } PrintWriter writer = new PrintWriter ( System . out ) ; if ( args . length >= 2 ) { if ( args [ 1 ] . compareToIgnoreCase ( "stdout" ) != 0 ) { System . out . println ( "Writing PDF content to " + args [ 1 ] ) ; writer = new PrintWriter ( new FileOutputStream ( new File ( args [ 1 ] ) ) ) ; } } int pageNum = - 1 ; if ( args . length >= 3 ) { pageNum = Integer . parseInt ( args [ 2 ] ) ; } if ( pageNum == - 1 ) { listContentStream ( new File ( args [ 0 ] ) , writer ) ; } else { listContentStream ( new File ( args [ 0 ] ) , pageNum , writer ) ; } writer . flush ( ) ; if ( args . length >= 2 ) { writer . close ( ) ; System . out . println ( "Finished writing content to " + args [ 1 ] ) ; } } catch ( Exception e ) { e . printStackTrace ( System . err ) ; } }
Writes information about each page in a PDF file to the specified file or System . out .