import java.io.*;

import javax.swing.JFileChooser;

import com.itextpdf.text.pdf.PdfReader;

public class Main {

	public static void main(String[] args) {

		try
		{
			String path = "";
			if ( 0 < args.length )
			{
				path = args[ 0 ];
			}
			
			if ( path == "" )
			{
				JFileChooser chooser = new JFileChooser();
				chooser.setCurrentDirectory( new File(".") );
			    int option = chooser.showOpenDialog( null );
			    if ( option == JFileChooser.APPROVE_OPTION )
			    {
			    	path = chooser.getSelectedFile().getAbsolutePath();
			    }
			}

			if ( path != "" )
			{
		    	PdfReader reader = new PdfReader( path );
		    	String js = reader.getJavaScript();
		        reader.close();
		
		        BufferedWriter writer = new BufferedWriter( new FileWriter( path + ".js" ) );
		        writer.write( js );
		        writer.close();
			}
		}
		catch (Exception e)
		{
		}
    }

}
