class ImageXRefViewer extends AbstractTool {

    static {
        addVersion("$Id: ImageXRefViewer.java 3271 2008-04-18 20:39:42Z xlv $");
    }

    /**
     * The total number of pictures inside the PDF.
     */
    int total_number_of_pictures = 0;
    /**
     * The spinner that will allow you to select an image.
     */
    JSpinner jSpinner = new JSpinner();
    /**
     * The panel that will show the images.
     */
    JPanel image_panel = new JPanel();
    /**
     * The layout with the images.
     */
    CardLayout layout = new CardLayout();

    /**
     * Creates a ViewImageXObjects object.
     */
    public ImageXRefViewer() {
        arguments.add(new FileArgument(this, "srcfile",
                "The file you want to inspect", false, new PdfFilter()));
    }

    /**
     * Shows the images that are in the PDF as Image XObjects.
     *
     * @param args String[]
     */
    public static void main(String[] args) {
        ImageXRefViewer tool = new ImageXRefViewer();
        if (args.length < 1) {
            System.err.println(tool.getUsage());
        }
        tool.setMainArguments(args);
        tool.execute();
    }

    /**
     * @return File
     * @throws InstantiationException on error
     * @see com.lowagie.toolbox.AbstractTool#getDestPathPDF()
     */
    protected File getDestPathPDF() throws InstantiationException {
        throw new InstantiationException("There is no file to show.");
    }

    /**
     * @see com.lowagie.toolbox.AbstractTool#createFrame()
     */
    protected void createFrame() {
        internalFrame = new JInternalFrame("View Image XObjects", true, false,
                true);
        internalFrame.setSize(500, 300);
        internalFrame.setJMenuBar(getMenubar());
        internalFrame.getContentPane().setLayout(new BorderLayout());

        JPanel master_panel = new JPanel();
        master_panel.setLayout(new BorderLayout());
        internalFrame.getContentPane().add(master_panel,
                java.awt.BorderLayout.CENTER);

        // images
        image_panel.setLayout(layout);
        jSpinner.addChangeListener(new SpinnerListener(this));
        image_panel.setBorder(BorderFactory.createEtchedBorder());

        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setViewportView(image_panel);
        master_panel.add(scrollPane, java.awt.BorderLayout.CENTER);

        // spinner

        JPanel spinner_panel = new JPanel();
        spinner_panel.setLayout(new BorderLayout());
        spinner_panel.add(jSpinner, java.awt.BorderLayout.CENTER);

        JLabel image_label = new JLabel();
        image_label.setHorizontalAlignment(SwingConstants.CENTER);
        image_label.setText("images");
        spinner_panel.add(image_label, java.awt.BorderLayout.NORTH);

        master_panel.add(spinner_panel, java.awt.BorderLayout.NORTH);

        System.out.println("=== Image XObject Viewer OPENED ===");
    }

    /**
     * @param arg StringArgument
     * @see com.lowagie.toolbox.AbstractTool#valueHasChanged(com.lowagie.toolbox.arguments.AbstractArgument)
     */
    public void valueHasChanged(AbstractArgument arg) {
        // do nothing
    }

    /**
     * Reflects the change event in the JSpinner object.
     *
     * @param evt ChangeEvent
     */
    public void propertyChange(ChangeEvent evt) {
        int picture = Integer.parseInt(jSpinner.getValue().toString());
        if (picture < 0) {
            picture = 0;
            jSpinner.setValue("0");
        }
        if (picture >= total_number_of_pictures) {
            picture = total_number_of_pictures - 1;
            jSpinner.setValue(String.valueOf(picture));
        }
        layout.show(image_panel, String.valueOf(picture));
        image_panel.repaint();
    }

    /**
     * @see com.lowagie.toolbox.AbstractTool#execute()
     */
    public void execute() {<FILL_FUNCTION_BODY>}

    class SpinnerListener implements ChangeListener {

        private ImageXRefViewer adaptee;

        SpinnerListener(ImageXRefViewer adaptee) {
            this.adaptee = adaptee;
        }

        /**
         * @param e ChangeEvent
         * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
         */
        public void stateChanged(ChangeEvent e) {
            adaptee.propertyChange(e);
        }
    }
}

        total_number_of_pictures = 0;
        try {
            if (getValue("srcfile") == null) {
                throw new InstantiationException(
                        "You need to choose a sourcefile");
            }
            EventDispatchingThread task = new EventDispatchingThread() {
                public Object construct() {
                    try {
                        PdfReader reader = new PdfReader(
                                ((File) getValue("srcfile")).getAbsolutePath());
                        for (int i = 0; i < reader.getXrefSize(); i++) {
                            PdfObject pdfobj = reader.getPdfObject(i);
                            if (pdfobj != null) {
                                if (pdfobj.isStream()) {
                                    PdfStream pdfdict = (PdfStream) pdfobj;
                                    PdfObject pdfsubtype = pdfdict
                                            .get(PdfName.SUBTYPE);
                                    if (pdfsubtype == null) {
                                        continue;
                                    }
                                    if (!pdfsubtype.toString().equals(
                                            PdfName.IMAGE.toString())) {
                                        continue;
                                    }
                                    System.out.println("total_number_of_pictures: "
                                            + total_number_of_pictures);
                                    System.out.println("height:"
                                            + pdfdict.get(PdfName.HEIGHT));
                                    System.out.println("width:"
                                            + pdfdict.get(PdfName.WIDTH));
                                    System.out.println("bitspercomponent:"
                                            + pdfdict.get(PdfName.BITSPERCOMPONENT));
                                    byte[] barr = PdfReader
                                            .getStreamBytesRaw((PRStream) pdfdict);
                                    java.awt.Image im = Toolkit
                                            .getDefaultToolkit().createImage(barr);
                                    javax.swing.ImageIcon ii = new javax.swing.ImageIcon(im);

                                    JLabel label = new JLabel();
                                    label.setIcon(ii);
                                    image_panel.add(label, String.valueOf(total_number_of_pictures++));
                                }
                            }
                        }
                    } catch (InstantiationException | IOException ex) {
                    }
                    internalFrame.setCursor(Cursor.getDefaultCursor());
                    return null;
                }
            };
            internalFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            task.start();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(internalFrame, e.getMessage(), e
                    .getClass().getName(), JOptionPane.ERROR_MESSAGE);
            System.err.println(e.getMessage());
        }
    
<methods>public void <init>() ,public void actionPerformed(java.awt.event.ActionEvent) ,public abstract void execute() ,public ArrayList<com.lowagie.toolbox.arguments.AbstractArgument> getArguments() ,public javax.swing.JInternalFrame getInternalFrame() ,public javax.swing.JMenuBar getMenubar() ,public java.lang.String getUsage() ,public java.lang.Object getValue(java.lang.String) throws java.lang.InstantiationException,public void setArguments(ArrayList<com.lowagie.toolbox.arguments.AbstractArgument>) ,public void setInternalFrame(javax.swing.JInternalFrame) ,public void setMainArguments(java.lang.String[]) ,public void setMenubar(javax.swing.JMenuBar) ,public abstract void valueHasChanged(com.lowagie.toolbox.arguments.AbstractArgument) <variables>public static final int MENU_EXECUTE,public static final int MENU_EXECUTE_PRINT,public static final int MENU_EXECUTE_PRINT_SILENT,public static final int MENU_EXECUTE_SHOW,protected ArrayList<com.lowagie.toolbox.arguments.AbstractArgument> arguments,private java.awt.Desktop awtdesktop,protected javax.swing.JInternalFrame internalFrame,private javax.swing.JMenuBar menubar,protected int menuoptions,public static ArrayList<java.lang.String> versionsarray