#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <windowsx.h> 
#include <math.h>

//define for VerySetFunction
#define Very_Set_MultiPage		101
#define Very_Set_ImagePosAndSize	104
#define Very_Set_Encrypt 		105
#define Very_Set_Font			106
#define Very_Set_NewOrClosePage		109
#define Very_Set_BookMark		110
#define Very_Set_ViewerPreferences	121
#define Very_Set_PageOrientation	122
#define Very_Set_Line_Dash		123
#define Very_Set_Line_Flat		124
#define Very_Set_Line_Join		125
#define Very_Set_Line_Cap		126
#define Very_Set_Line_MiterLimit	127

#define Very_Set_Link_BorderStyle	128
#define Very_Set_Link_BorderDash	129
#define Very_Set_Link_Web		130
#define Very_Set_Link_Local		132

#define Very_Set_Text_Matrix		133
#define Very_Set_Text_Leading		134
#define Very_Set_Text_Rise		135
#define Very_Set_Text_HorizScaling	136
#define Very_Set_Text_Rendering		137
#define Very_Set_Text_CharSpace		138
#define Very_Set_Text_WordSpace		139


//define for VeryGetFunction
#define Very_Get_ImagePageCount		201
#define Very_Get_ImageSizeW		202
#define Very_Get_ImageSizeH		203
#define Very_Get_ImageDpiX		204
#define Very_Get_ImageDpiY		205
#define Very_Get_PdfPageCount		206
#define Very_Get_PdfCurrentPageSize	209
#define Very_Get_StringWidth		250
#define Very_Get_StringHeight		251

//define for VeryAddText
#define Very_DT_LEFT			0
#define Very_DT_CENTER			1
#define Very_DT_RIGHT			2
#define Very_DT_WORDBREAK		0x10
#define Very_DT_CALCRECT		0x400

typedef long	(__stdcall *VeryCreate)(char *);
typedef long	(__stdcall *VeryOpen)(char *);
typedef void	(__stdcall *VeryClose)(long);
typedef long	(__stdcall *VeryAddInfo)(long,char*,char*,char*,char*,char*);
typedef long	(__stdcall *VerySetFunction)(long,long func_code,long para1,long para2,char *para3,char *para4);
typedef long	(__stdcall *VeryGetFunction)(long,long func_code,long para1,long para2,char *para3,char *para4);

typedef long	(__stdcall *VeryAddImage)(long,char *);
typedef long	(__stdcall *VeryAddImageData)(long,char *,long ,long ,long );

typedef long	(__stdcall *VeryAddTextEx)(long,long,long,char *,long );
typedef long	(__stdcall *VeryAddText)(long,long,long,long,long,char *,long ,long,long);
typedef long	(__stdcall *VeryAddTxt)(long id,char *szTxtName,long color,
				   long width,long height,long AutoNewLine,long AutoWidthAdjust,
				   long LeftMargin,long RightMargin,long TopMargin,long BottomMargin,
				   long TabSize);

typedef long	(__stdcall *VeryAddLine    )(long ,long ,long ,long ,long ,long ,long );
typedef long	(__stdcall *VeryAddRect    )(long ,long ,long ,long ,long ,long ,long ,long ,long );
typedef long	(__stdcall *VeryAddCircle  )(long ,long ,long ,long ,long ,long ,long ,long );
typedef long	(__stdcall *VeryAddEllipse )(long ,long ,long ,long ,long ,long ,long ,long ,long );
typedef long	(__stdcall *VeryAddPolygon )(long id,LPPOINT lpPoints, int nCount,
			long side_width,long side_color,long flagFill,long fill_color);
typedef long	(__stdcall *VeryAddCurveTo )(long id,long sx_,long sy_,long x1,long y1,
			long x2,long y2,long x3,long y3,long side_width,long side_color);


HMODULE				g_hVeryW=NULL;

VeryCreate			pVeryCreate;
VeryOpen			pVeryOpen;
VeryAddImage			pVeryAddImage;
VeryAddImageData		pVeryAddImageData;
VeryClose			pVeryClose;	
VeryAddInfo			pVeryAddInfo;	
VerySetFunction			pVerySetFunction;
VeryGetFunction			pVeryGetFunction;
VeryAddTextEx			pVeryAddTextEx;
VeryAddText			pVeryAddText;
VeryAddTxt			pVeryAddTxt;
VeryAddLine			pVeryAddLine;
VeryAddRect			pVeryAddRect;
VeryAddCircle			pVeryAddCircle;
VeryAddEllipse			pVeryAddEllipse;
VeryAddPolygon			pVeryAddPolygon;
VeryAddCurveTo			pVeryAddCurveTo;

void	GetModulePath(char *out_path,char *in_name);
BOOL	LoadVeryWDll(void);
void	FreeVeryWDll();


void GetModulePath(char *out_path,char *in_name)
{
	char *p;
	GetModuleFileName(NULL,out_path,256);
	p =strrchr(out_path,'\\');
	p[1]=0;
	strcat(out_path,in_name);
}

BOOL LoadVeryWDll()
{
	char path[_MAX_PATH];
	GetModulePath(path,"verywrite.dll");
	g_hVeryW=LoadLibrary(path);
	if(g_hVeryW==NULL)
		goto Failer;

	pVeryCreate=(VeryCreate)GetProcAddress(g_hVeryW,"VeryCreate");
	if(pVeryCreate==NULL)
		goto Failer;
	pVeryOpen=(VeryOpen)GetProcAddress(g_hVeryW,"VeryOpen");
	if(pVeryOpen==NULL)
		goto Failer;
	pVeryAddImage=(VeryAddImage)GetProcAddress(g_hVeryW,"VeryAddImage");
	if(pVeryAddImage==NULL)
		goto Failer;
	pVeryAddImageData=(VeryAddImageData)GetProcAddress(g_hVeryW,"VeryAddImageData");
	if(pVeryAddImageData==NULL)
		goto Failer;
	pVeryClose=(VeryClose)GetProcAddress(g_hVeryW,"VeryClose");
	if(pVeryClose==NULL)
		goto Failer;
	pVeryAddInfo=(VeryAddInfo)GetProcAddress(g_hVeryW,"VeryAddInfo");
	if(pVeryAddInfo==NULL)
		goto Failer;
	pVerySetFunction=(VerySetFunction)GetProcAddress(g_hVeryW,"VerySetFunction");
	if(pVerySetFunction==NULL)
		goto Failer;
	pVeryGetFunction=(VeryGetFunction)GetProcAddress(g_hVeryW,"VeryGetFunction");
	if(pVeryGetFunction==NULL)
		goto Failer;
	pVeryAddTextEx=(VeryAddTextEx)GetProcAddress(g_hVeryW,"VeryAddTextEx");
	if(pVeryAddTextEx==NULL)
		goto Failer;
	pVeryAddText=(VeryAddText)GetProcAddress(g_hVeryW,"VeryAddText");
	if(pVeryAddText==NULL)
		goto Failer;
	pVeryAddTxt=(VeryAddTxt)GetProcAddress(g_hVeryW,"VeryAddTxt");
	if(pVeryAddTxt==NULL)
		goto Failer;
	pVeryAddLine=(VeryAddLine)GetProcAddress(g_hVeryW,"VeryAddLine");
	if(pVeryAddLine==NULL)
		goto Failer;
	pVeryAddRect=(VeryAddRect)GetProcAddress(g_hVeryW,"VeryAddRect");
	if(pVeryAddRect==NULL)
		goto Failer;
	pVeryAddCircle=(VeryAddCircle)GetProcAddress(g_hVeryW,"VeryAddCircle");
	if(pVeryAddCircle==NULL)
		goto Failer;
	pVeryAddEllipse=(VeryAddEllipse)GetProcAddress(g_hVeryW,"VeryAddEllipse");
	if(pVeryAddEllipse==NULL)
		goto Failer;
	pVeryAddPolygon=(VeryAddPolygon)GetProcAddress(g_hVeryW,"VeryAddPolygon");
	if(pVeryAddPolygon==NULL)
		goto Failer;
	pVeryAddCurveTo=(VeryAddCurveTo)GetProcAddress(g_hVeryW,"VeryAddCurveTo");
	if(pVeryAddCurveTo==NULL)
		goto Failer;
	return TRUE;
Failer:
	FreeVeryWDll(); 
	return FALSE;

}

void FreeVeryWDll()
{
	if(g_hVeryW==NULL)
		return ;
	FreeLibrary(g_hVeryW);
	g_hVeryW=NULL;
}



void AddImageData(long id)
{
	char buf[32];
	char buf2[32];
	long iret;
	int i,j;
	int temp1,temp2;
	int red,green,blue;
	int MemImageWidth=640;
	int MemImageHeight=640;
	int color=24;//can equal 1 and 8 and 24
	char *MemData = (char *)malloc(MemImageWidth*MemImageHeight*3);
	for(i=0;i<MemImageHeight - 1;i++)
	{
		for(j=0;j<MemImageWidth - 1;j++)
		{
			temp1=i&8;
			temp2=j&8;
			if(temp1|temp2)
			{
				red=255;
				green = blue = 0;
			}
			else
			{
				red = 0;
				green = 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;
		}
	}

	//new page
	iret=pVerySetFunction(id,Very_Set_NewOrClosePage,MemImageWidth*2,MemImageHeight*2,0,0);
	//set image size
	iret=pVerySetFunction(id,Very_Set_ImagePosAndSize,
		MemImageWidth/2,MemImageHeight/2,
		ltoa(MemImageWidth,buf,10),ltoa(MemImageHeight,buf2,10));
	//add image one
	pVeryAddImageData(id,MemData,MemImageWidth,MemImageHeight,color);

	int pagewidth,pageheight;
	pVeryGetFunction(id,Very_Get_PdfCurrentPageSize,(long)&pagewidth,(long)&pageheight,0,0);
	pVerySetFunction(id,Very_Set_Font,1,60,"Times New Roman,Bold",0);
	pVeryAddText(id,0,100,pagewidth,60,"Memory Image Example",RGB(0,0,0),-1,Very_DT_CENTER);
	//close the page
	iret=pVerySetFunction(id,Very_Set_NewOrClosePage,0,0,0,0);


	free(MemData);
	MemData=NULL;
}

void AddTIFFImage(long id)
{
	char szImageFile[256];

	GetModulePath(szImageFile,"multipage.tif");
	//add bookmark
	int parentBookmark = pVerySetFunction(id, Very_Set_BookMark, 0, 0,"bookmark one",0);
	
	//get multi page tiff page nums
	int pagenum=pVeryGetFunction(id,Very_Get_ImagePageCount,0,0,szImageFile,0);
	if(pagenum>4)
	{
		//set multi page tiff convert
		int beginpage=2;
		int pagenums=2;
		pVerySetFunction(id,Very_Set_MultiPage,beginpage,pagenums,0,0);
	}
	if(pagenum)
		pVeryAddImage(id,szImageFile);
}
void AddWMFImage(long id)
{
	char szImageFile[256];

	GetModulePath(szImageFile,"test.wmf");
	pVeryAddImage(id,szImageFile);
}
void AddJPGImage(long id)
{
	long width,height,xdpi,ydpi;
	char szImageFile[256];

	GetModulePath(szImageFile,"test1.jpg");
	//add bookmark
	pVerySetFunction(id,Very_Set_BookMark,0,0,"bookmark two",0);
	int pagenum=pVeryGetFunction(id,Very_Get_ImagePageCount,0,0,szImageFile,0);
	for(int i = 1; i <= pagenum; i++)
	{
		char buf[32];
		char buf2[32];
		long iret;
		iret=pVeryGetFunction(id,Very_Get_ImageSizeW,(long)&width,(long)&height,szImageFile,ltoa(i,buf,10));
		//Get image dpi (Resolution)
		iret=pVeryGetFunction(id,Very_Get_ImageDpiX,(long)&xdpi,(long)&ydpi,szImageFile,ltoa(i,buf,10));
		if(xdpi>0&&ydpi>0){
			width  = (long)(width * (72.0/xdpi));
			height = (long)(height* (72.0/ydpi));
		}
		//new page
		iret=pVerySetFunction(id,Very_Set_NewOrClosePage,width,height,0,0);
		//set image size
		iret=pVerySetFunction(id,Very_Set_ImagePosAndSize,0,0,ltoa(width,buf,10),ltoa(height,buf2,10));
		//add image one
		iret=pVerySetFunction(id,Very_Set_MultiPage,i,1,0,0);
		iret=pVeryAddImage(id,szImageFile);
		//close the page
		iret=pVerySetFunction(id,Very_Set_NewOrClosePage,0,0,0,0);
	}
}
void AddText(long id)
{
	char* samp_text = "abcdefgABCDEFG12345!#$%&+-@?";
	int xx = 100;
	int yy = 180;
	//new a page for a3
	pVerySetFunction(id,Very_Set_NewOrClosePage,1,1,0,0);
	//add bookmark
	int book1 = pVerySetFunction(id,Very_Set_BookMark,0,0,"bookmark four-1",0);
		int book2 = pVerySetFunction(id,Very_Set_BookMark,book1,0,"bookmark four-2",0);
			int book3 = pVerySetFunction(id,Very_Set_BookMark,book2,0,"bookmark four-3",0);
				int book4 = pVerySetFunction(id,Very_Set_BookMark,book3,0,"bookmark four-4",0);
		int book5 = pVerySetFunction(id,Very_Set_BookMark,book1,0,"bookmark four-5",0);
	
	//set system font and size
	pVerySetFunction(id,Very_Set_Font,100,32,0,0);
	pVeryAddTextEx(id,xx,yy+=50,samp_text,RGB(0,0,0));
	pVerySetFunction(id,Very_Set_Font,101,32,0,0);
	pVeryAddTextEx(id,xx,yy+=50,samp_text,RGB(0,0,0));
	pVerySetFunction(id,Very_Set_Font,102,32,0,0);
	pVeryAddTextEx(id,xx,yy+=50,samp_text,RGB(0,0,0));
	pVerySetFunction(id,Very_Set_Font,103,32,0,0);
	pVeryAddTextEx(id,xx,yy+=50,samp_text,RGB(0,0,0));
	
	pVerySetFunction(id,Very_Set_Font,200,32,0,0);
	pVeryAddTextEx(id,xx,yy+=50,samp_text,RGB(0,0,0));
	pVerySetFunction(id,Very_Set_Font,201,32,0,0);
	pVeryAddTextEx(id,xx,yy+=50,samp_text,RGB(0,0,0));
	pVerySetFunction(id,Very_Set_Font,202,32,0,0);
	pVeryAddTextEx(id,xx,yy+=50,samp_text,RGB(0,0,0));
	pVerySetFunction(id,Very_Set_Font,203,32,0,0);
	pVeryAddTextEx(id,xx,yy+=50,samp_text,RGB(0,0,0));

	pVerySetFunction(id,Very_Set_Font,300,32,0,0);
	pVeryAddTextEx(id,xx,yy+=50,samp_text,RGB(0,0,0));
	pVerySetFunction(id,Very_Set_Font,301,32,0,0);
	pVeryAddTextEx(id,xx,yy+=50,samp_text,RGB(0,0,0));
	pVerySetFunction(id,Very_Set_Font,302,32,0,0);
	pVeryAddTextEx(id,xx,yy+=50,samp_text,RGB(0,0,0));
	pVerySetFunction(id,Very_Set_Font,303,32,0,0);
	pVeryAddTextEx(id,xx,yy+=50,samp_text,RGB(0,0,0));

	pVerySetFunction(id,Very_Set_Font,400,32,0,0);
	pVeryAddTextEx(id,xx,yy+=50,samp_text,RGB(0,0,0));

	yy+=40;
	pVerySetFunction(id,Very_Set_Font,1,32,"Arial",0);
	pVeryAddTextEx(id,xx,yy+=50,samp_text,RGB(0,0,0));
	pVerySetFunction(id,Very_Set_Font,1,32,"Arial,Bold",0);
	pVeryAddTextEx(id,xx,yy+=50,samp_text,RGB(0,0,0));
	pVerySetFunction(id,Very_Set_Font,1,32,"Arial,Italic",0);
	pVeryAddTextEx(id,xx,yy+=50,samp_text,RGB(0,0,0));
	pVerySetFunction(id,Very_Set_Font,1,32,"Arial,Bold,Italic",0);
	pVeryAddTextEx(id,xx,yy+=50,samp_text,RGB(0,0,0));

	//set font and size
	pVerySetFunction(id,Very_Set_Font,203,32,0,0);
	
	{
		char string[]="Show text in this rectangle, show text in this rectangle.";
		//width =pVeryGetFunction(id,Very_Get_StringWidth,0,0,string,0);
		//height=pVeryGetFunction(id,Very_Get_StringHeight,0,0,string,0);
		//add text for rect
		int width=200;  
		int height=0;
		pVeryAddText(id,1,1,(long)&width,(long)&height,string,
			RGB(0,0,255),RGB(255,0,255),Very_DT_WORDBREAK|Very_DT_CALCRECT); 
		pVeryAddText(id,1,1,width,height,string,
			RGB(0,0,255),RGB(255,0,255),Very_DT_WORDBREAK|Very_DT_CENTER); 
		//pVeryAddText(id,1,1,width,height,string,
		//			 RGB(0,0,255),RGB(255,0,255),Very_DT_WORDBREAK|Very_DT_CENTER); 
	}

//#define Very_Set_Link_BorderDash		129
//#define Very_Set_Link_Web		130
//#define 		132

	pVerySetFunction(id,Very_Set_Link_BorderStyle,0,2,0,0);//solid line, line width = 2
	pVerySetFunction(id,Very_Set_Link_Web,RGB(255,0,0),0,"250,40,500,120","www.verypdf.com");
	pVeryAddTextEx(id,260,50,"verypdf.com",RGB(0,0,0));

	pVerySetFunction(id,Very_Set_Link_BorderStyle,1,2,0,0);//dash line, line width = 2
	pVerySetFunction(id,Very_Set_Link_BorderDash,12,6,0,0);
	pVerySetFunction(id,Very_Set_Link_Local,RGB(0,255,0),2,"250,150,500,230","fitpage");
	pVeryAddTextEx(id,260,160,"Goto page 2",RGB(0,0,0));

	pVerySetFunction(id,Very_Set_Link_BorderStyle,0,0,0,0);//solid line, line width = 2
	pVerySetFunction(id,Very_Set_Link_Web,RGB(0,0,255),0,"520,40,770,120","mailto:support@verypdf.com");
	pVeryAddTextEx(id,530,50,"E-mail",RGB(0,0,0));

	//Close this page
	pVerySetFunction(id,Very_Set_NewOrClosePage,0,0,0,0);
}

void AddLineAndRect(long id)
{
	//new a page for b5
	pVerySetFunction(id,Very_Set_NewOrClosePage,2,2,0,0);
	//add bookmark
	int parentBookmark0  = pVerySetFunction(id, Very_Set_BookMark, 0, 0,"bookmark five:0",0);
		int parentBookmark1 = pVerySetFunction(id,Very_Set_BookMark,parentBookmark0,0,"bookmark five:1",0);
			int parentBookmark2 = pVerySetFunction(id,Very_Set_BookMark,parentBookmark1,0,"bookmark five:2",0);
		    parentBookmark1 = pVerySetFunction(id,Very_Set_BookMark,parentBookmark0,0,"bookmark five:1-1",0);

	int pagewidth,pageheight;
	pVeryGetFunction(id,Very_Get_PdfCurrentPageSize,(long)&pagewidth,(long)&pageheight,0,0);
	pVeryAddRect(id,20,20,pagewidth-20,pageheight-20,3,RGB(0,255,0),1,RGB(0xFC,0xFC,0xFC));

	int yy = 40;
	//add graphic
	pVeryAddLine(id,30,yy,300,yy,1,RGB(0,0,0)); yy+=20;
	pVeryAddLine(id,30,yy,300,yy,2,RGB(0,0,0)); yy+=20;
	pVeryAddLine(id,30,yy,300,yy,4,RGB(0,0,0)); yy+=20;

	//dash
	pVerySetFunction(id,Very_Set_Line_Dash,3,3,0,0);
	pVeryAddLine(id,30,yy,300,yy,2,RGB(0,0,0)); yy+=20;

	pVerySetFunction(id,Very_Set_Line_Dash,6,12,0,0);
	pVeryAddLine(id,30,yy,300,yy,2,RGB(0,0,0)); yy+=20;

	pVerySetFunction(id,Very_Set_Line_Dash,12,6,0,0);
	pVeryAddLine(id,30,yy,300,yy,2,RGB(0,0,0)); yy+=20;

	//flat
	pVerySetFunction(id,Very_Set_Line_Dash,24,12,0,0);
	pVerySetFunction(id,Very_Set_Line_Flat,50,0,0,0);
	pVeryAddLine(id,30,yy,300,yy,10,RGB(0,0,0)); yy+=60;

	//join
	pVerySetFunction(id,Very_Set_Line_Dash,0,0,0,0);
	pVerySetFunction(id,Very_Set_Line_Join,0,0,0,0);
	pVeryAddLine(id,30 ,yy,150,yy-40,10,RGB(0,255,0));
	pVeryAddLine(id,300,yy,150,yy-40,10,RGB(0,255,0)); yy+=60;

	pVerySetFunction(id,Very_Set_Line_Cap,1,0,0,0);
	pVerySetFunction(id,Very_Set_Line_Join,1,0,0,0);
	pVeryAddLine(id,30 ,yy,150,yy-40,10,RGB(0,255,0));
	pVeryAddLine(id,300,yy,150,yy-40,10,RGB(0,255,0)); yy+=60;

	pVerySetFunction(id,Very_Set_Line_Cap,2,0,0,0);
	pVerySetFunction(id,Very_Set_Line_Join,2,0,0,0);
	pVeryAddLine(id,30 ,yy,150,yy-40,10,RGB(0,255,0));
	pVeryAddLine(id,300,yy,150,yy-40,10,RGB(0,255,0)); yy+=20;

	//cap
	pVerySetFunction(id,Very_Set_Line_Cap,0,0,0,0);
	pVeryAddLine(id,30,yy,300,yy,10,RGB(0,0,255)); yy+=20;

	pVerySetFunction(id,Very_Set_Line_Cap,1,0,0,0);
	pVeryAddLine(id,30,yy,300,yy,10,RGB(0,0,255)); yy+=20;
	
	pVerySetFunction(id,Very_Set_Line_Cap,2,0,0,0);
	pVeryAddLine(id,30,yy,300,yy,10,RGB(0,0,255)); yy+=20;

	//Set to default style
	pVerySetFunction(id,Very_Set_Line_Cap,0,0,0,0);
	pVerySetFunction(id,Very_Set_Line_Join,0,0,0,0);

	//Rectangle
	yy = 40;
	pVeryAddRect(id, 350, yy, 550,yy+40, 10, RGB(0,0,0),0,0); yy+=60;

	pVerySetFunction(id,Very_Set_Line_Join,1,0,0,0);
	pVeryAddRect(id, 350, yy, 550,yy+40, 10, RGB(0,0,0),0,0); yy+=60;

	pVerySetFunction(id,Very_Set_Line_Join,0,0,0,0);
	pVeryAddRect(id, 350, yy, 550,yy+40, 2, RGB(255,0,0),1,RGB(255,0,0)); yy+=60;

	pVeryAddRect(id, 350, yy, 550,yy+40, 2, RGB(0,0,0),1,RGB(255,0,0)); yy+=100;

	//Circle
	pVeryAddCircle(id, (350+550)/2, yy, 40, 2, RGB(0,0,0),0,RGB(255,0,0)); yy+=100;
	pVeryAddCircle(id, (350+550)/2, yy, 40, 2, RGB(0,0,0),1,RGB(255,0,0)); yy+=100;

	//Ellipse
	pVeryAddEllipse(id, 350, yy, 550,yy+40, 2, RGB(0,0,0),0,RGB(255,0,0)); yy+=100;
	pVeryAddEllipse(id, 350, yy, 550,yy+40, 2, RGB(0,0,0),1,RGB(255,0,0)); yy+=100;

	//Polygon
	POINT pt[6];
	pt[0].x = 180;
	pt[0].y = 420;
	pt[1].x = pt[0].x-100;
	pt[1].y = pt[0].y+50;
	pt[2].x = pt[1].x+50;
	pt[2].y = pt[1].y+100;
	pt[3].x = pt[2].x+100;
	pt[3].y = pt[2].y;
	pt[4].x = pt[3].x+50;
	pt[4].y = pt[3].y-100;
	pt[5].x = pt[0].x;
	pt[5].y = pt[0].y;
	pVeryAddPolygon(id, &pt[0], 6, 20, RGB(0,0,0),1,RGB(255,0,0)); yy+=100;

	pVerySetFunction(id,Very_Set_Line_Cap,1,0,0,0);
	pVerySetFunction(id,Very_Set_Line_Join,1,0,0,0);
	pt[0].x = 180;
	pt[0].y = 600;
	pt[1].x = pt[0].x-100;
	pt[1].y = pt[0].y+50;
	pt[2].x = pt[1].x+50;
	pt[2].y = pt[1].y+100;
	pt[3].x = pt[2].x+100;
	pt[3].y = pt[2].y;
	pt[4].x = pt[3].x+50;
	pt[4].y = pt[3].y-100;
	pt[5].x = pt[0].x;
	pt[5].y = pt[0].y;
	pVeryAddPolygon(id, &pt[0], 6, 20, RGB(0,0,0),1,RGB(255,0,0)); yy+=100;

//	pVerySetFunction(id,Very_Set_Line_Cap,1,0,0,0);
//	pVerySetFunction(id,Very_Set_Line_Join,2,0,0,0);
//	pt[0].x = 480;
//	pt[0].y = 600;
//	pt[1].x = pt[0].x-100;
//	pt[1].y = pt[0].y+50;
//	pt[2].x = pt[1].x+50;
//	pt[2].y = pt[1].y+100;
//	pt[3].x = pt[2].x+100;
//	pt[3].y = pt[2].y;
//	pt[4].x = pt[3].x+50;
//	pt[4].y = pt[3].y-100;
//	pt[5].x = pt[0].x;
//	pt[5].y = pt[0].y;
//	pVeryAddPolygon(id, &pt[0], 6, 20, RGB(0,0,0),1,RGB(255,0,0)); yy+=100;

	pVeryAddCurveTo(id, 0, pageheight, 86, pageheight-108, 201, pageheight-158, 216, pageheight-86,
		5,RGB(0,0,255));

	//Close this page
	pVerySetFunction(id,Very_Set_NewOrClosePage,0,0,0,0);
}
void AddTextFile(long id)
{
	char szImageFile[256];
	GetModulePath(szImageFile,"test.txt");
	pVerySetFunction(id,Very_Set_Font,200,16,0,0);
	pVeryAddTxt(id,szImageFile,0,0,0,1,1,64,64,64,64,4);
}
void AddTextExample2(long id)
{
	char* samp_text = "abcdefgABCDEFG12345!#$%&+-@?";
	int xx = 30;
	int yy = 50;

	//new page
	int iret=pVerySetFunction(id,Very_Set_NewOrClosePage,2,2,0,0);

	int pagewidth,pageheight;
	pVeryGetFunction(id,Very_Get_PdfCurrentPageSize,(long)&pagewidth,(long)&pageheight,0,0);

	pVerySetFunction(id,Very_Set_Font,1,32,"Times New Roman,Bold",0);
	pVeryAddText(id,0,10,pagewidth,60,"Font Example 2",RGB(0,0,0),-1,Very_DT_CENTER);

	pVerySetFunction(id,Very_Set_Font,300,8,0,0);
	pVeryAddTextEx(id,xx,yy+=30,samp_text,RGB(0,0,0));
	pVerySetFunction(id,Very_Set_Font,300,12,0,0);
	pVeryAddTextEx(id,xx,yy+=30,samp_text,RGB(0,0,0));
	pVerySetFunction(id,Very_Set_Font,300,18,0,0);
	pVeryAddTextEx(id,xx,yy+=30,samp_text,RGB(0,0,0));
	pVerySetFunction(id,Very_Set_Font,300,27,0,0);
	pVeryAddTextEx(id,xx,yy+=30,samp_text,RGB(0,0,0));
	pVerySetFunction(id,Very_Set_Font,300,40,0,0);
	pVeryAddTextEx(id,xx,yy+=30,samp_text,RGB(0,0,0));


	pVerySetFunction(id,Very_Set_Font,300,27,0,0);
	{
		// Rotating text
		float angle = 30.0;                   // A rotation of 30 degrees.
		float rad = float(angle / 180 * 3.141592); // Calcurate the radian value.
		char  szTextMatrix[200];
		sprintf(szTextMatrix,"%f,%f,%f,%f,%f,%f",cos(rad), sin(rad), -sin(rad), cos(rad), 0.0, 0.0);
		pVerySetFunction(id,Very_Set_Text_Matrix,0,0,szTextMatrix,0);
		pVeryAddTextEx(id,xx,yy+=150,"ABCabc123",RGB(255,0,0));
	}
	{
		// Skewing text
		float _angle1 = 10.0;
		float _angle2 = 20.0;
		float _rad1 = float(_angle1 / 180 * 3.141592);
		float _rad2 = float(_angle2 / 180 * 3.141592);

		float m2 = (float)tan(_rad1);
		float m3 = (float)tan(_rad2);
		char  szTextMatrix[200];
		sprintf(szTextMatrix,"%f,%f,%f,%f,%f,%f",1.0, m2, m3, 1.0, 0.0, 0.0);
		pVerySetFunction(id,Very_Set_Text_Matrix,0,0,szTextMatrix,0);
		pVeryAddTextEx(id,xx,yy+=100,"ABCabc123",RGB(0,255,0));
	}
	{
		// Scaling text (X direction)
		pVerySetFunction(id,Very_Set_Text_Matrix,0,0,"1.5,0.0,0.0,1.0,0.0,0.0",0);
		pVeryAddTextEx(id,xx,yy+=100,"ABCabc123",RGB(0,0,255));
		
		// Scaling text (Y direction)
		pVerySetFunction(id,Very_Set_Text_Matrix,0,0,"1.0,0.0,0.0,2.0,0.0,0.0",0);
		pVeryAddTextEx(id,xx,yy+=100,"ABCabc123",RGB(0,255,255));
	}
	xx = 250;
	yy = 250;
	pVerySetFunction(id,Very_Set_Text_Matrix,0,0,"1,0,0,1,0,0",0);
	pVeryAddTextEx(id,xx,yy,"ABCabc123",RGB(0,0,255));
	pVerySetFunction(id,Very_Set_Text_Rise,10,0,0,0);
	pVeryAddTextEx(id,-1,-1,"Rasing",RGB(0,0,255));
	
	yy += 50;
	pVeryAddTextEx(id,xx,yy,"ABCabc123",RGB(0,0,255));
	pVerySetFunction(id,Very_Set_Text_HorizScaling,50,0,0,0);
	pVeryAddTextEx(id,-1,-1,"HorizScaling",RGB(0,0,255));

	yy += 50;
	pVerySetFunction(id,Very_Set_Text_HorizScaling,100,0,0,0);
	pVeryAddTextEx(id,xx,yy,"CharSpace",RGB(0,0,255));
	pVerySetFunction(id,Very_Set_Text_CharSpace,10,0,0,0);
	pVeryAddTextEx(id,-1,-1,"CharSpace",RGB(0,0,255));

	yy += 50;
	pVerySetFunction(id,Very_Set_Text_CharSpace,0,0,0,0);
	pVeryAddTextEx(id,xx,yy,"Word Space",RGB(0,0,255));
	pVerySetFunction(id,Very_Set_Text_WordSpace,20,0,0,0);
	pVeryAddTextEx(id,-1,-1,"Word Space",RGB(0,0,255));
	
	pVerySetFunction(id,Very_Set_Text_WordSpace,0,0,0,0);
	pVerySetFunction(id,Very_Set_Text_Rendering,0,0,0,0);
	pVeryAddTextEx(id,xx,yy += 50,"Render0",RGB(0,0,255));
	pVerySetFunction(id,Very_Set_Text_Rendering,1,0,0,0);
	pVeryAddTextEx(id,xx,yy += 50,"Render1",RGB(0,0,255));
	pVerySetFunction(id,Very_Set_Text_Rendering,2,0,0,0);
	pVeryAddTextEx(id,xx,yy += 50,"Render2",RGB(0,0,255));
	pVerySetFunction(id,Very_Set_Text_Rendering,3,0,0,0);
	pVeryAddTextEx(id,xx,yy += 50,"Render3",RGB(0,0,255));
	pVerySetFunction(id,Very_Set_Text_Rendering,4,0,0,0);
	pVeryAddTextEx(id,xx,yy += 50,"Render4",RGB(0,0,255));

	//Close current page
	iret=pVerySetFunction(id,Very_Set_NewOrClosePage,0,0,0,0);
}
void CharTable(long id)
{
	char buf[50];
static const int PAGE_WIDTH = 420;
static const int PAGE_HEIGHT = 400;
static const int CELL_WIDTH = 20;
static const int CELL_HEIGHT = 20;
static const int CELL_HEADER = 10;

	//new a page for b5
	pVerySetFunction(id,Very_Set_NewOrClosePage,PAGE_WIDTH,PAGE_HEIGHT,0,0);
	
	// Draw vertical lines.
	for (int i = 0; i <= 17; i++) 
	{
		int x = i * CELL_WIDTH + 40;
		pVeryAddLine(id,x,40,x,PAGE_HEIGHT - 60,1,RGB(0,0,0));
		if (i > 0 && i <= 16) 
		{
			sprintf(buf, "%X", i - 1);
			pVeryAddTextEx(id,x + 5,40,buf,RGB(255,0,0));
		}
	}
	
	// Draw horizontal lines.
	for (int j = 0; j <= 15; j++)
	{
		int y = j * CELL_HEIGHT + 40;
		pVeryAddLine(id,40,y,PAGE_WIDTH - 40,y,1,RGB(0,0,0));
		if (j < 14)
		{
			sprintf(buf, "%X", j+2);
			pVeryAddTextEx(id,45,y + 20,buf,RGB(255,0,0));
		}
	}

	{
		int i, j;
		
		for (i = 1; i < 17; i++)
		{
			for (j = 1; j < 17; j++) 
			{
				//int y = PAGE_HEIGHT - 55 - ((i - 1) * CELL_HEIGHT);
				int y = (i * CELL_HEIGHT);
				int x = j * CELL_WIDTH + 45;
				
				buf[1] = 0x00;
				buf[0] = (i - 1) * 16 + (j - 1);
				if (buf[0] >= 32) 
				{
					pVeryAddTextEx(id,x,y,buf,RGB(0,0,0));
				}
			}
		}
	}
	//Close this page
	pVerySetFunction(id,Very_Set_NewOrClosePage,0,0,0,0);
}
void main()
{
	char szPDFFile[256];
	char szImageFile[256];
	long id;

	memset(szPDFFile,0,256);
	memset(szImageFile,0,256);

	if(!LoadVeryWDll())
		return ;

	GetModulePath(szPDFFile,"append.pdf");
	id=pVeryOpen(szPDFFile);
	if(id>0)
	{
		pVeryAddInfo(id,"Title","Subject","Author","Keywords","Creator");
		pVerySetFunction(id,Very_Set_ViewerPreferences,4+4096,2,0,0);

		//add image file types
		AddTIFFImage(id);

		AddJPGImage(id);
		
		AddWMFImage(id);
		
		//add bookmark
		pVerySetFunction(id,Very_Set_BookMark,0,0,"bookmark three",0);
		//add image four, the example for bit 24 bmp
		AddImageData(id);

		AddText(id);

		AddLineAndRect(id);

		AddTextFile(id);

		AddTextExample2(id);

		CharTable(id);

		pVeryClose(id);
	}
	FreeVeryWDll();

	ShellExecute(NULL,"open",szPDFFile,NULL,NULL,SW_SHOWNORMAL);
}