
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";

	static String res_path = "../../lib";

	public static void main(String[] args)
	{
		PDF2Image.Init(username, company, lic_key, res_path);
		if (example == 1)
		{
			// The simplest PDF2Image program: Pass an explicit command-line string.
			//
			// This example converts 'tiger.pdf' to 'tiger.png'
			// To convert all PDF documents in 'TestFiles' folder simply delete 'tiger.pdf'
			// from the command string.
			// 
			// For a detailed explanation of all commands, please refer to PDF2Image SDK User 
			// Manual. Also, PDF2Image Command-Line application is a great tool to experiment 
			// with the available options.

			//use the default callback
			PDF2ImageCallback cb = new PDF2ImageCallback();
			PDF2Image.Run("-f png -o ../TestOutput/test1 ../TestFiles/tiger.pdf", cb, null);
		}
		else if (example == 2)
		{
			// An example of how to use PDF2Image SDK to implement a command-line application
			// for converting PDF pages to images.
			String s = "";
			for (int i = 0; i < args.length; i++)
			{
				s += args[i] + " ";
			}

			PDF2Image.Run(s, new PDF2ImageCallback(), null);
		}
		else if (example == 3)
		{

			// An example of how to dynamically build a command string based on 
			// user settings...
			//
			// Please note that this sample does not cover all possible options offered by 
			// PDF2Image. For a detailed explanation of all commands, please refer to 
			// PDF2Image SDK User Manual.
			String output_folder = "../TestOutput/test2";
			String open_password = "secret";
			String output_format = "png"; // or png, png8, gif, tif, bmp, raw, etc.

			// Controls for the output name of rasterized/converted images...
			String filename_prefix = "";
			int filename_digits = 4;

			boolean multipage = false; // used if the output format is 'tiff'.
			boolean grayscale = false;

			// the output image resolution (DPI := Dots Pet Inch).
			int dpi = 96;

			// dimensions of the output image in pixels
			// Used if dpi is 0.	
			int hres = 500, vres = 500;

			// compression_quality is used to control lossy compression 
			// algorithms (e.g. jpeg)
			int compression_quality = 60;

			int rotate = 0;  // rotates the page 90/180/270 degrees
			boolean antialias = true;
			boolean printmode = true;

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

			if (output_folder != "") s += "-o " + output_folder + " ";
			if (open_password != "") s += "-p " + open_password + " ";
			if (output_format != "") s += "-f " + output_format + " ";

			if (filename_prefix != "") s += "--prefix " + filename_prefix + " ";
			if (filename_digits > 0) s += "--digits " + filename_digits + " ";

			if (multipage) s += "--multipage ";
			if (grayscale) s += "--gray ";

			if (dpi > 0)
			{
				s += "--dpi " + dpi + " ";
			}
			else
			{  // use explicit image resolution
				s += "--hres " + hres + " --vres " + vres + " ";
			}

			if (compression_quality > 0)
			{
				s += "-q " + compression_quality + " ";
			}

			if (antialias == false) s += "--nosmooth ";
			if (printmode) s += "--printmode ";

			if (rotate == 90) s += "--rotate 90 ";
			if (rotate == 180) s += "--rotate 180 ";
			if (rotate == 270) s += "--rotate 270 ";

			// specify input PDF files and folders...
			s += "../TestFiles/tiger.pdf ";
			s += "../TestFiles/tai962.pdf ";
			// s += "c:/my_pdf_folder "; etc ...

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

			// Execute the command string.
			PDF2Image.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 PDF2ImageCallback
{
	//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

}
