class PdfContentReaderTool {

    /**
     * Shows the detail of a dictionary. This is similar to the PdfLister functionality.
     *
     * @param dic the dictionary of which you want the detail
     * @return a String representation of the dictionary
     */
    public static String getDictionaryDetail(PdfDictionary dic) {
        return getDictionaryDetail(dic, 0);
    }

    /**
     * Shows the detail of a dictionary.
     *
     * @param dic   the dictionary of which you want the detail
     * @param depth the depth of the current dictionary (for nested dictionaries)
     * @return a String representation of the dictionary
     */
    public static String getDictionaryDetail(PdfDictionary dic, int depth) {
        StringBuilder builder = new StringBuilder();
        builder.append('(');
        List<PdfName> subDictionaries = new ArrayList<>();
        for (PdfName key : dic.getKeys()) {
            PdfObject val = dic.getDirectObject(key);
            if (val.isDictionary()) {
                subDictionaries.add(key);
            }
            builder.append(key);
            builder.append('=');
            builder.append(val);
            builder.append(", ");
        }
        builder.setLength(builder.length() - 2);
        builder.append(')');
        PdfName pdfSubDictionaryName;
        for (Object subDictionary : subDictionaries) {
            pdfSubDictionaryName = (PdfName) subDictionary;
            builder.append('\n');
            for (int i = 0; i < depth + 1; i++) {
                builder.append('\t');
            }
            builder.append("Subdictionary ");
            builder.append(pdfSubDictionaryName);
            builder.append(" = ");
            builder.append(getDictionaryDetail(
                    dic.getAsDict(pdfSubDictionaryName), depth + 1));
        }
        return builder.toString();
    }

    /**
     * Writes information about a specific page from PdfReader to the specified output stream.
     *
     * @param reader  the PdfReader to read the page content from
     * @param pageNum the page number to read
     * @param out     the output stream to send the content to
     * @throws IOException thrown when an I/O operation goes wrong
     * @since 2.1.5
     */
    public static void listContentStreamForPage(PdfReader reader, int pageNum, PrintWriter out)
            throws IOException {
        out.println("==============Page " + pageNum + "====================");
        out.println("- - - - - Dictionary - - - - - -");
        PdfDictionary pageDictionary = reader.getPageN(pageNum);
        out.println(getDictionaryDetail(pageDictionary));
        out.println("- - - - - Content Stream - - - - - -");
        RandomAccessFileOrArray f = reader.getSafeFile();

        byte[] contentBytes = reader.getPageContent(pageNum, f);
        f.close();

        InputStream is = new ByteArrayInputStream(contentBytes);
        int ch;
        while ((ch = is.read()) != -1) {
            out.print((char) ch);
        }

        out.println("\n- - - - - Text Extraction - - - - - -");
        PdfTextExtractor extractor = new PdfTextExtractor(reader,
                new MarkedUpTextAssembler(reader));
        String extractedText = extractor.getTextFromPage(pageNum);
        if (extractedText.length() != 0) {
            out.println(extractedText);
        } else {
            out.println("No text found on page " + pageNum);
        }

        out.println();

    }

    /**
     * Writes information about each page in a PDF file to the specified output stream.
     *
     * @param pdfFile a File instance referring to a PDF file
     * @param out     the output stream to send the content to
     * @throws IOException thrown when an I/O operation goes wrong
     * @since 2.1.5
     */
    public static void listContentStream(File pdfFile, PrintWriter out)
            throws IOException {
        PdfReader reader = new PdfReader(pdfFile.getCanonicalPath());

        int maxPageNum = reader.getNumberOfPages();

        for (int pageNum = 1; pageNum <= maxPageNum; pageNum++) {
            listContentStreamForPage(reader, pageNum, out);
        }

    }

    /**
     * Writes information about the specified page in a PDF file to the specified output stream.
     *
     * @param pdfFile a File instance referring to a PDF file
     * @param pageNum the page number to read
     * @param out     the output stream to send the content to
     * @throws IOException thrown when an I/O operation goes wrong
     * @since 2.1.5
     */
    public static void listContentStream(File pdfFile, int pageNum,
            PrintWriter out) throws IOException {
        PdfReader reader = new PdfReader(pdfFile.getCanonicalPath());

        listContentStreamForPage(reader, pageNum, out);
    }

    /**
     * Writes information about each page in a PDF file to the specified file, or System.out.
     *
     * @param args the arguments passed to the command line
     */
    public static void main(String[] args) {<FILL_FUNCTION_BODY>}

}

        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);
        }
    
<no_super_class>