import java.util.ArrayList;
import pdftron.*;


public class test
{
	//chooses which example to run
	public static int example = 1;

	// You can modify the following lines with your registration information.
	static String username = "John Doe";
	static String company = "My Company";
	static String lic_key = "my license key";


	public static void main(String[] args)
	{
		PDFSecure.Init(username, company, lic_key);
		if (example == 1)
		{
			/// A simple PDF PageMaster program: Pass an explicit command-line string.
			///
			/// This example will split the file bookmark.pdf and create
			/// one new file for each page.
			///
			/// The -s parameter specifies that split is the operation
			/// The --digits parameter specifies that the numbers in resulting
			/// file names should have at least 2 digits
			/// The -o parameter specifies the output directory.  In this
			/// case that files should be created in the TestOutput/test1 directory
			
			//use the default callback
			PDFSecureCallback cb = new PDFSecureCallback();
			PDFSecure.Run("-o ../TestOutput/test1 -s 128 -u secret ../TestFiles", cb, null);
		}
		else if (example == 2)
		{
			// An example of how to use PageMaster SDK to implement a command-line 
			// application for processing of PDF documents.
			String s = "";
			for (int i = 0; i < args.length; i++)
			{
				s += args[i] + " ";
			}

			PDFSecure.Run(s, new PDFSecureCallback(), null);
		}
		else if (example == 3)
		{
			// A more complicated example that illustrates how to dynamically build a command 
			// string based on user security settings...
			// Please note that this sample does not cover all possible options offered by 
			// PDFSecure. For a detailed explanation of all commands, please refer to PDFSecure 
			// User Manual.
			boolean linearized_output = true;
			boolean aes_encryption = false;
			String output_folder = "../TestOutput/test1";
			String open_password = "mypass";
			String title = "My Title";
			String author = "Joe Doe";
			String subject = "My Subject";
			String keywords = "key1 key2 key2";
			String creator = "PDFTron PDFNet";
			String producer = "PDFSecure";

			// Permissions
			boolean printing = false;
			boolean high_rez_printing = false;
			boolean doc_modifications = true;  // Changing the document
			boolean content_extraction = true;
			boolean commenting = true;
			boolean forms_editing = true;
			boolean accessibility = true;
			boolean document_assembly = true;

			// Given the above settings build a command string.
			String s = "";

			if (output_folder != "")
				s += "-o " + output_folder + " ";

			if (aes_encryption)
			{
				s += "-s AES ";  // Use 128-bit AES (Advanced Encryption Standard); Supported in PDF 1.6 (Acrobat 7) and above.
			}
			else
			{
				s += "-s 128 ";  // Use 128-bit RC4 encryption. Supported in PDF 1.4 (Acrobat 5) and above.
				// To remove security use:
				//  s += "-s R";  etc.
			}

			if (open_password != "")
				s += "--userpass " + open_password + " ";

			// Set the permissions.
			s += "-e a -d \"";
			if (printing == false) s += "p";
			if (high_rez_printing == false) s += "h";
			if (doc_modifications == false) s += "m";
			if (content_extraction == false) s += "c";
			if (commenting == false) s += "o";
			if (forms_editing == false) s += "f";
			if (accessibility == false) s += "x";
			if (document_assembly == false) s += "s";
			s += "\" ";

			if (linearized_output) s += "-l ";

			// Set document information.
			if (title != "") s += "--title \"" + title + "\" ";
			if (author != "") s += "--author \"" + author + "\" ";
			if (subject != "") s += "--subject \"" + subject + "\" ";
			if (keywords != "") s += "--keywords \"" + keywords + "\" ";
			if (creator != "") s += "--creator \"" + creator + "\" ";
			if (producer != "") s += "--producer \"" + producer + "\" ";

			// specify input files and folders...
			s += "../TestFiles/black.pdf ";
			s += "../TestFiles/blue.pdf ";
			// ...


			//an arraylist to store the saved file path(s)
			ArrayList saved_files = new ArrayList();


			// Execute the command string.
			PDFSecure.Run(s, new MyCallback(), saved_files);

			//print the saved file(s)
			System.out.println("The Saved Files Are:");
			for (int i = 0; i < saved_files.size(); i++)
			{
				System.out.println(saved_files.get(i));
			}
		}

		System.out.println("Done.");


	}


}
//customized callback class
class MyCallback extends PDFSecureCallback
{
	//OutFilename is called each time a file is saved
	//with the saved file path
	protected void OutFilename(String msg, Object user_data)
	{
		//store each file path in the saved_files arraylist
		if (msg != null && user_data != null)
			((ArrayList)user_data).add(msg);
	}

	//The following functions can also be changed

	//protected void Error(String msg, Object user_data) is called with
	//an error message when an error occurs
	
	//protected void Msg(String msg, Object user_data) is called with
	//any other messages
	
	//protected String GetPass(String msg, Object user_data) is called
	//when a password is needed for continued execution

}

