import java.io.*;

import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;

public class Main {

	public static void main(String[] args) {

		try
		{
			if ( args.length < 3 )
			{
				System.out.println( "JS2PDF input.pdf input.js output.pdf" );
				System.exit( 0 );
			}
			
			String path = args[ 0 ];
	    	PdfReader reader = new PdfReader( path );
	    	
	        BufferedReader jsReader = new BufferedReader( new FileReader( args[ 1 ] ) );
	        String js = "";
	        while ( jsReader.ready() )
	        {
	        	js += jsReader.readLine() + "\n";
	        }
	        jsReader.close();
	        
	        PdfStamper stamper = new PdfStamper( reader, new FileOutputStream( args[ 2 ] ) );
	        stamper.addJavaScript( js );
	        stamper.close();
	        
	        reader.close();
		}
		catch (Exception e)
		{
		}
    }

}
