using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;



using System.Runtime.InteropServices; //requirement class

namespace dlltest
{
	/// <summary>
	/// 
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{

		[DllImport("imagetopdf",  CallingConvention=CallingConvention.StdCall)] 
		public static extern int ApCreate (string lpFileName); 
 
		[DllImport("imagetopdf",  CallingConvention=CallingConvention.StdCall)] 
		public static extern int ApOpen (string lpFileName); 

		[DllImport("imagetopdf",  CallingConvention=CallingConvention.StdCall)] 
		public static extern void ApClose (int id); 

		[DllImport("imagetopdf",  CallingConvention=CallingConvention.StdCall)] 
		public static extern int ApAddImage (int id ,string lpFileName);

		[DllImport("imagetopdf",  CallingConvention=CallingConvention.StdCall)] 
		public static extern int ApAddImageData (int id ,byte[] MemData ,int  width ,int  height ,int  color);

		[DllImport("imagetopdf",  CallingConvention=CallingConvention.StdCall)] 
		public static extern int ApAddTextEx (int id, int x, int y, string str, int color); 

		[DllImport("imagetopdf",  CallingConvention=CallingConvention.StdCall)] 
		public static extern int ApAddText (int id, int x, int y, int width, int height, string str, int color, int bkcolor, int lformat); 

		[DllImport("imagetopdf",  CallingConvention=CallingConvention.StdCall)] 
		public static extern int ApAddTxt (int id, string lpFileName, int color, int pagewidth, int pageheight, int AutoNewLine, int AutoWidthAdjust, int LeftMargin, int RightMargin, int TopMargin, int BottomMargin, int TabSize); 

		[DllImport("imagetopdf",  CallingConvention=CallingConvention.StdCall)] 
		public static extern int ApAddLine (int id, int sx, int sy, int ex, int ey, int side_width, int side_color); 

		[DllImport("imagetopdf",  CallingConvention=CallingConvention.StdCall)] 
		public static extern int ApAddRect (int id, int sx, int sy, int ex, int ey, int side_width, int side_color, int flagFill, int fill_color); 

		[DllImport("imagetopdf",  CallingConvention=CallingConvention.StdCall)] 
		public static extern int ApAddInfo (int id, string Title, string Subject, string Author, string Keywords, string Creator); 

		[DllImport("imagetopdf",  CallingConvention=CallingConvention.StdCall)] 
		public static extern int ApSetFunction (int id, int func_code, int Para1, int Para2, string szPara3, string szPara4); 

		[DllImport("imagetopdf",  CallingConvention=CallingConvention.StdCall)] 
		public static extern int ApGetFunction (int id, int func_code, int Para1, int Para2, string szPara3, string szPara4); 
		
		[DllImport("imagetopdf",  CallingConvention=CallingConvention.StdCall)] 
		public static extern int ApGetFunction (int id, int func_code, ref int Para1, ref int Para2, string szPara3, string szPara4); 

		//**************************************************************************************

		//defined for ApSetFunction
		const int  Ap_Set_MultiPage				=101;
		const int  Ap_Set_ImagePosAndSize		=104;
		const int  Ap_Set_Encrypt 				=105;
		const int  Ap_Set_Font					=106;
		const int  Ap_Set_NewOrClosePage		=109;
		const int  Ap_Set_BookMark				=110;
		const int  Ap_Set_ViewerPreferences		=121;
		const int  Ap_Set_Orientation			=122;
		const int  Ap_Set_Recompress			=123;
		const int  Ap_Set_Skewcorrect			=126;
		const int  Ap_Set_JpegQuality			=128;

		//defined for ApGetFunction
		const int  Ap_Get_ImagePageCount		=201;
		const int  Ap_Get_ImageSizeW			=202;
		const int  Ap_Get_ImageSizeH			=203;
		const int  Ap_Get_ImageDpiX				=204;
		const int  Ap_Get_ImageDpiY				=205;
		const int  Ap_Get_PdfPageCount			=206;
		const int  Ap_Get_PdfCurrentPageSize	=209;
		const int  Ap_Get_StringWidth			=250;
		const int  Ap_Get_StringHeight			=251;
		const int  Ap_Get_Recomporess			=210;
		const int  Ap_Get_ImageBits				=211;

		//defined for ApAddText
		const int Ap_DT_LEFT = 0x0;
		const int Ap_DT_CENTER = 0x1;
		const int Ap_DT_RIGHT = 0x2;
		const int Ap_DT_WORDBREAK = 0x10;
		const int Ap_DT_CALCRECT = 0x400;
		const int Ap_DT_CALCRECTEX = 0x800;

		//defined permission
		const int permission_Print = 1;
		const int permission_Copy  = 2;
		const int permission_Modify= 4;


		//**************************************************************************************
		private int RGB(int r,int g,int b)
		{
			return ((int)(((r)|(((g))<<8))|(((b))<<16)));
			
		}

		//**************************************************************************************

		private void AddImageData(int id)
		{
			int i,j;
			int temp1,temp2;
			byte red,green,blue;
			int MemImageWidth=640;
			int MemImageHeight=640;
			int color=24;//can be equal 1 , 8 or 24
			byte[] MemData = new byte[MemImageWidth * MemImageHeight * 3];

			for(i=0;i<MemImageHeight - 1;i++)
			{
				for(j=0;j<MemImageWidth - 1;j++)
				{
					temp1 =i&8;
					temp2 =j&8;
					temp1 = temp1|temp2;
					if(temp1 != 0)
					{
						red=255;
						green = 0;
						blue = 0;
					}
					else
					{
						red = 0;
						green = 0;
						blue = 255;		
					}
					MemData[i * MemImageWidth * 3 + j * 3 + 0] = red;
					MemData[i * MemImageWidth * 3 + j * 3 + 1] = green;
					MemData[i * MemImageWidth * 3 + j * 3 + 2] = blue;
				}
			}

			//create page
			ApSetFunction(id,Ap_Set_NewOrClosePage,MemImageWidth,MemImageHeight,null,null);

			ApAddImageData(id,MemData,MemImageWidth,MemImageHeight,color);

			//close page
			ApSetFunction(id,Ap_Set_NewOrClosePage,0,0,null,null);

		}
		//**************************************************************************************

		//split image file
		private void One2Multiple(string pPdf,string pImage)
		{
			int id,pagecount,beginpage;
			string szPDFFile;
	
			//get multipage image page count
			pagecount = ApGetFunction(0,Ap_Get_ImagePageCount,0,0, pImage,null) ;
			for(beginpage=1; beginpage<=pagecount; beginpage++)
			{
				szPDFFile = string.Format("{0}{1}.pdf",pPdf,beginpage);
				if( (id = ApCreate(szPDFFile)) >0 )
				{
					ApSetFunction(id,Ap_Set_MultiPage,beginpage,1,null,null);	
					ApAddImage(id,pImage);
					ApClose(id);
				}
			}
		}

		//**************************************************************************************

		private void One2One(string pPdf,string pImage)
		{
			int id;

			if( (id=ApCreate(pPdf)) >0 )
			{
				ApAddImage(id,pImage);
				ApClose(id);
			}
		}
		//**************************************************************************************
		//merge image file
		private void Multiple2One(string pPdf,string[] pImage,int len)
		{	
			int id,i;
	
			if( (id=ApCreate(pPdf)) >0 )
			{
				for(i = 0; i < len; i++)
				{
					ApAddImage(id,pImage[i]);	
				}
				ApClose(id);
			}
		}

		//**************************************************************************************

		private void AppendPDF(string pPdf,string[] pImage,int len)
		{
			int id,i;

			for(i = 0; i < len; i++)
			{
				if( (id=ApOpen(pPdf)) >0 )//Append PDF file
				{
					ApAddImage(id,pImage[i]);
					ApClose(id);
				}
				else
					if( (id=ApCreate(pPdf)) >0 )//Create new PDF file
				{
					ApAddImage(id,pImage[i]);
					ApClose(id);
				}
			}
		
		}

		//**************************************************************************************


		private void RecompressTruecolorFile(string pPdf,string pImage)
		{
			int id;
			string szPDFFile;

			// recompress lzw
			szPDFFile = string.Format("{0}_lzw.pdf",pPdf);
			if( (id=ApCreate(szPDFFile)) >0 )
			{
				ApSetFunction(id,Ap_Set_Recompress,3,0,"lzw",null);
				ApAddImage(id,pImage);
				ApClose(id);
			}

			// recompress zip
			szPDFFile = string.Format("{0}_zip.pdf",pPdf);
			if( (id=ApCreate(szPDFFile)) >0 )
			{
				ApSetFunction(id,Ap_Set_Recompress,3,0,"zip",null);
				ApAddImage(id,pImage);
				ApClose(id);
			}

			// recompress packbits
			szPDFFile = string.Format("{0}_packbits.pdf",pPdf);
			if( (id=ApCreate(szPDFFile)) >0 )
			{
				ApSetFunction(id,Ap_Set_Recompress,3,0,"packbits",null);
				ApAddImage(id,pImage);
				ApClose(id);
			}

			// recompress jpeg,quality=100
			szPDFFile = string.Format("{0}_jpeg_100.pdf",pPdf);
			if( (id=ApCreate(szPDFFile)) >0 )
			{
				ApSetFunction(id,Ap_Set_Recompress,3,0,"jpeg",null);
				ApSetFunction(id,Ap_Set_JpegQuality,100,0,null,null);
				ApAddImage(id,pImage);
				ApClose(id);
			}

			// recompress jpeg,quality=50
			szPDFFile = string.Format("{0}_jpeg_50.pdf",pPdf);
			if( (id=ApCreate(szPDFFile)) >0 )
			{
				ApSetFunction(id,Ap_Set_Recompress,3,0,"jpeg",null);
				ApSetFunction(id,Ap_Set_JpegQuality,50,0,null,null);
				ApAddImage(id,pImage);
				ApClose(id);
			}

		}

		//**************************************************************************************

		private void RecompressGrayFile(string pPdf,string pImage)
		{
			int id;
			string szPDFFile;

			// recompress lzw
			szPDFFile = string.Format("{0}_lzw.pdf",pPdf);
			if( (id=ApCreate(szPDFFile)) >0 )
			{
				ApSetFunction(id,Ap_Set_Recompress,2,0,"lzw",null);
				ApAddImage(id,pImage);
				ApClose(id);
			}

			// recompress zip
			szPDFFile = string.Format("{0}_zip.pdf",pPdf);
			if( (id=ApCreate(szPDFFile)) >0 )
			{
				ApSetFunction(id,Ap_Set_Recompress,2,0,"zip",null);
				ApAddImage(id,pImage);
				ApClose(id);
			}

			// recompress packbits
			szPDFFile = string.Format("{0}_packbits.pdf",pPdf);
			if( (id=ApCreate(szPDFFile)) >0 )
			{
				ApSetFunction(id,Ap_Set_Recompress,2,0,"packbits",null);
				ApAddImage(id,pImage);
				ApClose(id);
			}

			// recompress jpeg, default quality=75
			szPDFFile = string.Format("{0}_jpeg.pdf",pPdf);
			if( (id=ApCreate(szPDFFile)) >0 )
			{
				ApSetFunction(id,Ap_Set_Recompress,2,0,"jpeg",null);
				ApAddImage(id,pImage);
				ApClose(id);
			}

		}
		//**************************************************************************************

		private void RecompressBlackWhiteFile(string pPdf,string pImage)
		{

			int id;
			string szPDFFile;

			// recompress lzw
			szPDFFile = string.Format("{0}_lzw.pdf",pPdf);
			if( (id=ApCreate(szPDFFile)) >0 )
			{
				ApSetFunction(id,Ap_Set_Recompress,1,0,"lzw",null);
				ApAddImage(id,pImage);
				ApClose(id);
			}

			// recompress zip
			szPDFFile = string.Format("{0}_zip.pdf",pPdf);
			if( (id=ApCreate(szPDFFile)) >0 )
			{
				ApSetFunction(id,Ap_Set_Recompress,1,0,"zip",null);
				ApAddImage(id,pImage);
				ApClose(id);
			}

			// recompress CCITT Group 3 fax encoding
			szPDFFile = string.Format("{0}_g3.pdf",pPdf);
			if( (id=ApCreate(szPDFFile)) >0 )
			{
				ApSetFunction(id,Ap_Set_Recompress,1,0,"g3",null);
				ApAddImage(id,pImage);
				ApClose(id);
			}

			// recompress CCITT Group 4 fax encoding
			szPDFFile = string.Format("{0}_g4.pdf",pPdf);
			if( (id=ApCreate(szPDFFile)) >0 )
			{
				ApSetFunction(id,Ap_Set_Recompress,1,0,"g4",null);
				ApAddImage(id,pImage);
				ApClose(id);
			}

		}

		//**************************************************************************************
		private void Recompress(string pPdf,string pImage)
		{
			int bits;
			bits = ApGetFunction(0,Ap_Get_ImageBits,0,0,pImage,null);	
			switch(bits)
			{
				case 1:
					RecompressBlackWhiteFile(pPdf,pImage);
					break;
				case 8:
					RecompressGrayFile(pPdf,pImage);
					break;
				case 24:
					RecompressTruecolorFile(pPdf,pImage);
					break;
				default :
					break;
			}

		}
		//**************************************************************************************



		private void Skewcorrect(string pPdf,string pImage)
		{
			int id;

			if( (id=ApCreate(pPdf)) >0 )
			{
				ApAddImage(id,pImage);

				//set skewcorrect
				ApSetFunction(id,Ap_Set_Skewcorrect,1,0,null,null);

				ApAddImage(id,pImage);		

				ApClose(id);	
			}

		}




		//**************************************************************************************

		private void PageSize(string pPdf,string pImage)
		{
			int id;
			float fZoom, zw,zh;
			int ImageWidth=0,ImageHeight=0,ImageWidth2,ImageHeight2,PageWidth,PageHeight;
			int xdpi=0,ydpi=0;

			if( (id=ApCreate(pPdf)) >0 )
			{
				//Get image width and height
				ApGetFunction(id,Ap_Get_ImageSizeW,ref ImageWidth,ref ImageHeight,pImage,null);
				//Get image dpi (Resolution)
				ApGetFunction(id,Ap_Get_ImageDpiX,ref xdpi,ref ydpi,pImage,null);

				//keep image dpi (resolution)
				ImageWidth2  = (int)(ImageWidth * (72.0/xdpi));
				ImageHeight2 = (int)(ImageHeight* (72.0/ydpi));

				ApSetFunction(id,Ap_Set_NewOrClosePage,ImageWidth2,ImageHeight2,null,null);
				ApAddImage(id,pImage);

				//page size with image size
				ApSetFunction(id,Ap_Set_NewOrClosePage,ImageWidth,ImageHeight,null,null);
				ApAddImage(id,pImage);

				//A4
				ApSetFunction(id,Ap_Set_NewOrClosePage,2,2,null,null);
				ApSetFunction(id,Ap_Set_ImagePosAndSize,0,0,
								string.Format("{0}",ImageWidth),string.Format("{0}",ImageHeight));
				ApAddImage(id,pImage);

				//custom page size and fit width/height 
				PageWidth=768;
				PageHeight=1024;
				ApSetFunction(id,Ap_Set_NewOrClosePage,PageWidth,PageHeight,null,null);
				zw = (float)PageWidth/ImageWidth;
				zh = (float)PageHeight/ImageHeight;
				fZoom= zw < zh ? zw : zh;
				ImageWidth = (int)(ImageWidth * fZoom);
				ImageHeight=(int)(ImageHeight * fZoom);
				ApSetFunction( id,Ap_Set_ImagePosAndSize,(PageWidth-ImageWidth)/2,(PageHeight-ImageHeight)/2,
								string.Format("{0}",ImageWidth),string.Format("{0}",ImageHeight));
				ApAddImage(id,pImage);
		
				ApClose(id);
			}

		}
		//**************************************************************************************
		private void PageLayout(string pPdf,string[] pImage,int len)
		{
			int id,i,nPos=1;
			int nPages,index;
			int PageWidth,PageHeight;

			PageWidth=768;
			PageHeight=1024;

			if( (id=ApCreate(pPdf)) >0 )
			{
				for(i = 0; i < len; i++)
				{
					//get pages
					nPages = ApGetFunction(id,Ap_Get_ImagePageCount,0,0,pImage[i],null);
					
					for(index = 1; index <= nPages; index++)
					{
						switch(nPos%4)
						{
							case 1:
							{
								//new page
								ApSetFunction(id,Ap_Set_NewOrClosePage,PageWidth,PageHeight,null,null);
								//set image posion
								ApSetFunction(id,Ap_Set_ImagePosAndSize,0,0,
									string.Format("{0}",PageWidth/2),string.Format("{0}",PageHeight/2));
								ApSetFunction(id,Ap_Set_MultiPage,index,1,null,null);
								ApAddImage(id,pImage[i]);
							}break;
							case 2:
							{
								ApSetFunction(id,Ap_Set_ImagePosAndSize,PageWidth/2,0,
									string.Format("{0}",PageWidth/2),string.Format("{0}",PageHeight/2));
								ApSetFunction(id,Ap_Set_MultiPage,index,1,null,null);
								ApAddImage(id,pImage[i]);
							}break;
							case 3:
							{
								ApSetFunction(id,Ap_Set_ImagePosAndSize,0,PageHeight/2,
									string.Format("{0}",PageWidth/2),string.Format("{0}",PageHeight/2));
								ApSetFunction(id,Ap_Set_MultiPage,index,1,null,null);
								ApAddImage(id,pImage[i]);
							}break;
							case 0:
							{
								ApSetFunction(id,Ap_Set_ImagePosAndSize,PageWidth/2,PageHeight/2,
									string.Format("{0}",PageWidth/2),string.Format("{0}",PageHeight/2));
								ApSetFunction(id,Ap_Set_MultiPage,index,1,null,null);
								ApAddImage(id,pImage[i]);
								//close page
								ApSetFunction(id,Ap_Set_NewOrClosePage,0,0,null,null);
							}break;
						}			
						nPos++;
					}
				}
				ApClose(id);
			}

		}
		//**************************************************************************************

		private void PageOrientation(string pPdf,string pImage)
		{
			int id;
			string szPDFFile ;
			int nOrientation;

			nOrientation=90;
			szPDFFile = string.Format("{0}_90.pdf",pPdf);
			if( (id=ApCreate(szPDFFile)) >0 )
			{	
				ApSetFunction(id,Ap_Set_Orientation,nOrientation,0,null,null);
				ApAddImage(id,pImage);
				ApClose(id);
			}

			nOrientation=180;
			szPDFFile = string.Format("{0}_180.pdf",pPdf);
			if( (id=ApCreate(szPDFFile)) >0 )
			{	
				ApSetFunction(id,Ap_Set_Orientation,nOrientation,0,null,null);
				ApAddImage(id,pImage);
				ApClose(id);
			}

			nOrientation=270;
			szPDFFile = string.Format("{0}_270.pdf",pPdf);
			if( (id=ApCreate(szPDFFile)) >0 )
			{	
				ApSetFunction(id,Ap_Set_Orientation,nOrientation,0,null,null);
				ApAddImage(id,pImage);
				ApClose(id);
			}

		}
		//----------------------------------------------------------------------------------------

		private void Watermark(string pPdf,string[] pImage,int len)
		{
			int id,i;
			int nPages,index;
			int ImageWidth=0,ImageHeight=0;
			int nPosX,nPosY;

			if( (id=ApCreate(pPdf)) >0 )
			{
				for(i = 0; i < len; i++)
				{
					nPages=ApGetFunction(id,Ap_Get_ImagePageCount,0,0,pImage[i],null);
					for(index=1; index<=nPages; index++)
					{
						//get image width and height
						ApGetFunction(id,Ap_Get_ImageSizeW,ref ImageWidth,ref ImageHeight,pImage[i],string.Format("{0}",index));
						//new page
						ApSetFunction(id,Ap_Set_NewOrClosePage,ImageWidth,ImageHeight,null,null);
						//set image pos
						ApSetFunction(id,Ap_Set_ImagePosAndSize,0,0,string.Format("{0}",ImageWidth),string.Format("{0}",ImageHeight));
			
						ApSetFunction(id,Ap_Set_MultiPage,index,1,null,null);
						ApAddImage(id,pImage[i]);
				
						//set system font and size
						ApSetFunction(id,Ap_Set_Font,1,32,"Arial",null);
						//add text
						nPosX=10;
						nPosY=ImageHeight/2;
						ApAddTextEx(id,nPosX,nPosY,"(c)Copyright XXXXXXXXXX",RGB(255,0,0));

						//close page
						ApSetFunction(id,Ap_Set_NewOrClosePage,0,0,null,null);
					}
				}
				ApClose(id);
			}
	
		}

		//----------------------------------------------------------------------------------------
		private void PDFsecurity(string pPdf,string pImage)
		{
			int id;

			if( (id=ApCreate(pPdf)) >0 )
			{
				ApSetFunction(id,Ap_Set_Encrypt,128,permission_Print+permission_Copy+permission_Modify,"owner","user");
				ApAddImage(id,pImage);
				ApClose(id);
			}

		}
		//----------------------------------------------------------------------------------------

		private void PDFInfo(string pPdf,string pImage)
		{
			int id;

			if( (id=ApCreate(pPdf)) >0 )
			{
				ApAddInfo(id,"Title","Subject","Author","Keywords","Creator");
				ApAddImage(id,pImage);
				ApClose(id);
			}
	
		}
		//----------------------------------------------------------------------------------------


		private void Bookmark(string pPdf,string pImage)
		{
			int beginpage;
			int pagecount;
			int id;
			string szBookmark;

			if( (id=ApCreate(pPdf)) >0 )
			{
				//get multi page image page count
				pagecount=ApGetFunction(id,Ap_Get_ImagePageCount,0,0,pImage,null);
				for(beginpage=1; beginpage <= pagecount; beginpage++)
				{
					//add bookmark
					szBookmark = string.Format("bookmark {0}",beginpage);
					ApSetFunction(id,Ap_Set_BookMark,0,0,szBookmark,null);
					//Add page
					ApSetFunction(id,Ap_Set_MultiPage,beginpage,1,null,null);			
					ApAddImage(id,pImage);
				}
				ApClose(id);
			}

		}

		//----------------------------------------------------------------------------------------

		private void ViewerPreferences(string pPdf,string pImage)
		{
			int id;

			if( (id=ApCreate(pPdf)) >0 )
			{
				ApSetFunction(id,Ap_Set_ViewerPreferences,4+4096,2,null,null);
				ApAddImage(id,pImage);
				ApClose(id);
			}
	
		}

		//----------------------------------------------------------------------------------------


		private void TextAndGraphics(string pPdf)
		{

			int id,width,height;
			string strings = "this is a text! this is a text! this is a text! this is a text!";

			if( (id=ApCreate(pPdf)) >0 )
			{
				//create a page for a3
				ApSetFunction(id,Ap_Set_NewOrClosePage,1,1,null,null);
				//set system font and size
				ApSetFunction(id,Ap_Set_Font,1,32,"Arial",null);
				//add text
				ApAddTextEx(id,300,300,"this is a text!",RGB(0,255,255));

				//set system font and size
				ApSetFunction(id,Ap_Set_Font,1,32,"Helvetica",null);
				//add text
				ApAddTextEx(id,300,400,"this is a text!",RGB(0,255,255));

				//set adobe font and size
				ApSetFunction(id,Ap_Set_Font,203,32,null,null);
				//add text with rectangle
				width =400;
				height=200;
				ApAddText(id,100,50,width,height,strings,RGB(0,0,255),RGB(255,0,255),Ap_DT_WORDBREAK|Ap_DT_CENTER); 

				//set system font and size
				ApSetFunction(id,Ap_Set_Font,1,32,"Verdana",null);
				//add text
				ApAddTextEx(id,300,500,"this is a text!",RGB(0,255,255));

				//create a page for b5
				ApSetFunction(id,Ap_Set_NewOrClosePage,4,4,null,null);
				//add graphic
				ApAddLine  (id,10,10,100,200,5,RGB(0,0,255));
				ApAddRect(id,20,210,300,400,3,RGB(0,255,0),1,RGB(255,0,255));
				//close page
				ApSetFunction(id,Ap_Set_NewOrClosePage,0,0,null,null);

				//add a txt file
				ApSetFunction(id,Ap_Set_Font,200,16,null,null);
				ApAddTxt(id,"test.txt",0,0,0,1,1,64,64,64,64,4);

				//add memory image 
				AddImageData(id);

				ApClose(id);
			}

		}


















//**************************************************************************************
		private System.Windows.Forms.Button button1;
		/// <summary>
		/// 
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// 
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent
			//
		}

		/// <summary>
		/// 
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.button1 = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(72, 112);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(136, 40);
			this.button1.TabIndex = 0;
			this.button1.Text = "Click it";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(292, 273);
			this.Controls.Add(this.button1);
			this.Name = "Form1";
			this.Text = "For C#.Net";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
		
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			string szMultiPage = "MultiPage.tif";
			string szBlackWhite = "BlackWhite.tif";
			string szGray = "Gray.tif";
			string szTrueColor = "TrueColor.tif";
			string szSkewcorrect = "Skewcorrect.tif";
			string szJpg="test.jpg";
			string szBmp="test.bmp";
			string szGif="test.gif";
			string szEmf="test.emf";
			string szWmf="test.wmf";
			string szDcx="test.dcx";
			string szPcx="test.pcx";
			string szPsd="test.psd";
			string[] input = new string [20];

			input[0] = szBlackWhite;
			input[1] = szGray;
			input[2] = szTrueColor;
			input[3] = szMultiPage;
			input[4] = szJpg;
			input[5] = szBmp;
			input[6] = szGif;
			input[7] = szEmf;
			input[8] = szWmf;
			input[9] = szDcx;
			input[10] =szPcx;
			input[11] =szPsd;

			One2Multiple("One2Multiple1",szMultiPage);
			One2Multiple("One2Multiple2",szDcx);
	
			One2One("One2One1.pdf",szMultiPage);
			One2One("One2One2.pdf",szDcx);

			Multiple2One("Multiple2One.pdf",input,12);

			AppendPDF("Append.pdf",input,2);

			
			//re-compress image files to PDFs
			Recompress("BlackWhite",szBlackWhite);
			Recompress("Gray",szGray);
			Recompress("TrueColor",szTrueColor);

			Skewcorrect("Skewcorrect.pdf",szSkewcorrect);

			PageSize("PageSize.pdf",szTrueColor);

			PageLayout("PageLayout.pdf",input,12);

			PageOrientation("PageOrientation",szMultiPage);

			Watermark("Watermark.pdf",input,12);

			PDFsecurity("Security.pdf",szTrueColor);

			PDFInfo("Information.pdf",szTrueColor);

			Bookmark("Bookmark.pdf",szMultiPage);

			ViewerPreferences("ViewerPreferences.pdf",szTrueColor);
	
			TextAndGraphics("TextAndGraphics.pdf");
			

			

		}
	}
}
