Esempio n. 1
0
		private static void pd_PrintPage(object sender,System.Drawing.Printing.PrintPageEventArgs e) {
			Graphics g=e.Graphics;
			g.SmoothingMode=SmoothingMode.HighQuality;
			Sheet sheet=SheetList[sheetsPrinted];
			SheetUtil.CalculateHeights(sheet,g);//this is here because of easy access to g.
			Font font;
			FontStyle fontstyle;
			//first, draw images------------------------------------------------------------------------------------
			foreach(SheetField field in sheet.SheetFields){
				if(field.FieldType!=SheetFieldType.Image){
					continue;
				}
				string filePathAndName=ODFileUtils.CombinePaths(SheetUtil.GetImagePath(),field.FieldName);
				Image img=null;//js consider switching this from an image to a bitmap
				if(field.FieldName=="Patient Info.gif") {
					img=Properties.Resources.Patient_Info;
				}
				else if(File.Exists(filePathAndName)) {
					img=Image.FromFile(filePathAndName);
				}
				else {
					continue;
				}
				g.DrawImage(img,field.XPos,field.YPos,field.Width,field.Height);
				img.Dispose();
				img=null;
			}
			//then, drawings--------------------------------------------------------------------------------------------
			Pen pen=new Pen(Brushes.Black,2f);
			string[] pointStr;
			List<Point> points;
			Point point;
			string[] xy;
			foreach(SheetField field in sheet.SheetFields){
				if(field.FieldType!=SheetFieldType.Drawing){
					continue;
				}
				pointStr=field.FieldValue.Split(';');
				points=new List<Point>();
				for(int p=0;p<pointStr.Length;p++){
					xy=pointStr[p].Split(',');
					if(xy.Length==2){
						point=new Point(PIn.Int(xy[0]),PIn.Int(xy[1]));
						points.Add(point);
					}
				}
				for(int i=1;i<points.Count;i++){
					g.DrawLine(pen,points[i-1].X,points[i-1].Y,points[i].X,points[i].Y);
				}
			}
			//then, rectangles and lines----------------------------------------------------------------------------------
			Pen pen2=new Pen(Brushes.Black,1f);
			foreach(SheetField field in sheet.SheetFields){
				if(field.FieldType==SheetFieldType.Rectangle){
					g.DrawRectangle(pen2,field.XPos,field.YPos,field.Width,field.Height);
				}
				if(field.FieldType==SheetFieldType.Line){
					g.DrawLine(pen2,field.XPos,field.YPos,
						field.XPos+field.Width,
						field.YPos+field.Height);
				}
			}
			//then, draw text-----------------------------------------------------------------------------------------------
			Bitmap doubleBuffer=new Bitmap(sheet.Width,sheet.Height);
			Graphics gfx=Graphics.FromImage(doubleBuffer);
			foreach(SheetField field in sheet.SheetFields){
				if(field.FieldType!=SheetFieldType.InputField
					&& field.FieldType!=SheetFieldType.OutputText
					&& field.FieldType!=SheetFieldType.StaticText)
				{
					continue;
				}
				fontstyle=FontStyle.Regular;
				if(field.FontIsBold){
					fontstyle=FontStyle.Bold;
				}
				font=new Font(field.FontName,field.FontSize,fontstyle);
				Plugins.HookAddCode(null,"SheetPrinting.pd_PrintPage_drawFieldLoop",field);
				GraphicsHelper.DrawString(g,gfx,field.FieldValue,font,Brushes.Black,field.Bounds);
				//g.DrawString(field.FieldValue,font,Brushes.Black,field.BoundsF);
			}
			gfx.Dispose();
			//then, checkboxes----------------------------------------------------------------------------------
			Pen pen3=new Pen(Brushes.Black,1.6f);
			foreach(SheetField field in sheet.SheetFields){
				if(field.FieldType!=SheetFieldType.CheckBox){
					continue;
				}
				if(field.FieldValue=="X"){
					g.DrawLine(pen3,field.XPos,field.YPos,field.XPos+field.Width,field.YPos+field.Height);
					g.DrawLine(pen3,field.XPos+field.Width,field.YPos,field.XPos,field.YPos+field.Height);
				}
			}
			//then signature boxes----------------------------------------------------------------------
			foreach(SheetField field in sheet.SheetFields){
				if(field.FieldType!=SheetFieldType.SigBox){
					continue;
				}
				SignatureBoxWrapper wrapper=new SignatureBoxWrapper();
				wrapper.Width=field.Width;
				wrapper.Height=field.Height;
				if(field.FieldValue.Length>0){//a signature is present
					bool sigIsTopaz=false;
					if(field.FieldValue[0]=='1'){
						sigIsTopaz=true;
					}
					string signature="";
					if(field.FieldValue.Length>1){
						signature=field.FieldValue.Substring(1);
					}
					string keyData=Sheets.GetSignatureKey(sheet);
					wrapper.FillSignature(sigIsTopaz,keyData,signature);
				}
				Bitmap sigBitmap=wrapper.GetSigImage();
				g.DrawImage(sigBitmap,field.XPos,field.YPos,field.Width-2,field.Height-2);
			}
			g.Dispose();
			//no logic yet for multiple pages on one sheet.
			sheetsPrinted++;
			//heightsCalculated=false;
			if(sheetsPrinted<SheetList.Count){
				e.HasMorePages=true;
			}
			else{
				e.HasMorePages=false;
				sheetsPrinted=0;
			}	
		}
Esempio n. 2
0
		public static void CreatePdfPage(Sheet sheet,PdfPage page) {
			page.Width=p(sheet.Width);//XUnit.FromInch((double)sheet.Width/100);  //new XUnit((double)sheet.Width/100,XGraphicsUnit.Inch);
			page.Height=p(sheet.Height);//new XUnit((double)sheet.Height/100,XGraphicsUnit.Inch);
			if(sheet.IsLandscape){
				page.Orientation=PageOrientation.Landscape;
			}
			XGraphics g=XGraphics.FromPdfPage(page);
			g.SmoothingMode=XSmoothingMode.HighQuality;
			//g.PageUnit=XGraphicsUnit. //wish they had pixel
			//XTextFormatter tf = new XTextFormatter(g);//needed for text wrap
			//tf.Alignment=XParagraphAlignment.Left;
			//pd.DefaultPageSettings.Landscape=
			//already done?:SheetUtil.CalculateHeights(sheet,g);//this is here because of easy access to g.
			XFont xfont;
			XFontStyle xfontstyle;
			//first, draw images--------------------------------------------------------------------------------------
			foreach(SheetField field in sheet.SheetFields){
				if(field.FieldType!=SheetFieldType.Image){
					continue;
				}
				string filePathAndName=ODFileUtils.CombinePaths(SheetUtil.GetImagePath(),field.FieldName);
				Bitmap bitmapOriginal=null;
				if(field.FieldName=="Patient Info.gif") {
					bitmapOriginal=Properties.Resources.Patient_Info;
				}
				else if(File.Exists(filePathAndName)) {
					bitmapOriginal=new Bitmap(filePathAndName);
				}
				else {
					continue;
				}
				Bitmap bitmapResampled=(Bitmap)bitmapOriginal.Clone();
				if(bitmapOriginal.HorizontalResolution!=96 || bitmapOriginal.VerticalResolution!=96){//to avoid slowdown for other pdfs
					//The scaling on the XGraphics.DrawImage() function causes unreadable output unless the image is in 96 DPI native format.
					//We use GDI here first to convert the image to the correct size and DPI, then pass the second image to XGraphics.DrawImage().
					bitmapResampled.Dispose();
					bitmapResampled=null;
					bitmapResampled=new Bitmap(field.Width,field.Height);
					Graphics gr=Graphics.FromImage(bitmapResampled);
					gr.DrawImage(bitmapOriginal,0,0,field.Width,field.Height);
					gr.Dispose();
				}
				g.DrawImage(bitmapResampled,p(field.XPos),p(field.YPos),p(field.Width),p(field.Height));
				bitmapResampled.Dispose();
				bitmapResampled=null;
				bitmapOriginal.Dispose();
				bitmapOriginal=null;
			}
			//then, drawings--------------------------------------------------------------------------------------------
			XPen pen=new XPen(XColors.Black,p(2));
			string[] pointStr;
			List<Point> points;
			Point point;
			string[] xy;
			foreach(SheetField field in sheet.SheetFields){
				if(field.FieldType!=SheetFieldType.Drawing){
					continue;
				}
				pointStr=field.FieldValue.Split(';');
				points=new List<Point>();
				for(int j=0;j<pointStr.Length;j++){
					xy=pointStr[j].Split(',');
					if(xy.Length==2){
						point=new Point(PIn.Int(xy[0]),PIn.Int(xy[1]));
						points.Add(point);
					}
				}
				for(int i=1;i<points.Count;i++){
					g.DrawLine(pen,p(points[i-1].X),p(points[i-1].Y),p(points[i].X),p(points[i].Y));
				}
			}
			//then, rectangles and lines----------------------------------------------------------------------------------
			XPen pen2=new XPen(XColors.Black,p(1));
			foreach(SheetField field in sheet.SheetFields){
				if(field.FieldType==SheetFieldType.Rectangle){
					g.DrawRectangle(pen2,p(field.XPos),p(field.YPos),p(field.Width),p(field.Height));
				}
				if(field.FieldType==SheetFieldType.Line){
					g.DrawLine(pen2,p(field.XPos),p(field.YPos),
						p(field.XPos+field.Width),
						p(field.YPos+field.Height));
				}
			}
			//then, draw text--------------------------------------------------------------------------------------------
			Bitmap doubleBuffer=new Bitmap(sheet.Width,sheet.Height);
			Graphics gfx=Graphics.FromImage(doubleBuffer);
			foreach(SheetField field in sheet.SheetFields){
				if(field.FieldType!=SheetFieldType.InputField
					&& field.FieldType!=SheetFieldType.OutputText
					&& field.FieldType!=SheetFieldType.StaticText)
				{
					continue;
				}
				xfontstyle=XFontStyle.Regular;
				if(field.FontIsBold){
					xfontstyle=XFontStyle.Bold;
				}
				xfont=new XFont(field.FontName,field.FontSize,xfontstyle);
				//xfont=new XFont(field.FontName,field.FontSize,xfontstyle);
				//Rectangle rect=new Rectangle((int)p(field.XPos),(int)p(field.YPos),(int)p(field.Width),(int)p(field.Height));
				XRect xrect=new XRect(p(field.XPos),p(field.YPos),p(field.Width),p(field.Height));
				//XStringFormat format=new XStringFormat();
				//tf.DrawString(field.FieldValue,font,XBrushes.Black,xrect,XStringFormats.TopLeft);
				GraphicsHelper.DrawStringX(g,gfx,1d/p(1),field.FieldValue,xfont,XBrushes.Black,xrect);
			}
			gfx.Dispose();
			//then, checkboxes----------------------------------------------------------------------------------
			XPen pen3=new XPen(XColors.Black,p(1.6f));
			foreach(SheetField field in sheet.SheetFields){
				if(field.FieldType!=SheetFieldType.CheckBox){
					continue;
				}
				if(field.FieldValue=="X"){
					g.DrawLine(pen3,p(field.XPos),p(field.YPos),p(field.XPos+field.Width),p(field.YPos+field.Height));
					g.DrawLine(pen3,p(field.XPos+field.Width),p(field.YPos),p(field.XPos),p(field.YPos+field.Height));
				}
			}
			//then signature boxes----------------------------------------------------------------------
			foreach(SheetField field in sheet.SheetFields){
				if(field.FieldType!=SheetFieldType.SigBox){
					continue;
				}
				SignatureBoxWrapper wrapper=new SignatureBoxWrapper();
				wrapper.Width=field.Width;
				wrapper.Height=field.Height;
				if(field.FieldValue.Length>0){//a signature is present
					bool sigIsTopaz=false;
					if(field.FieldValue[0]=='1'){
						sigIsTopaz=true;
					}
					string signature="";
					if(field.FieldValue.Length>1){
						signature=field.FieldValue.Substring(1);
					}
					string keyData=Sheets.GetSignatureKey(sheet);
					wrapper.FillSignature(sigIsTopaz,keyData,signature);
				}
				XImage sigBitmap=XImage.FromGdiPlusImage(wrapper.GetSigImage());
				g.DrawImage(sigBitmap,p(field.XPos),p(field.YPos),p(field.Width-2),p(field.Height-2));
			}
		}
Esempio n. 3
0
		public static void drawFieldSigBox(SheetField field,Sheet sheet,Graphics g,XGraphics gx) {
			SignatureBoxWrapper wrapper=new SignatureBoxWrapper();
			wrapper.Width=field.Width;
			wrapper.Height=field.Height;
			if(field.FieldValue.Length>0) {//a signature is present
				bool sigIsTopaz=false;
				if(field.FieldValue[0]=='1') {
					sigIsTopaz=true;
				}
				string signature="";
				if(field.FieldValue.Length>1) {
					signature=field.FieldValue.Substring(1);
				}
				string keyData=Sheets.GetSignatureKey(sheet);
				wrapper.FillSignature(sigIsTopaz,keyData,signature);
			}
			if(g!=null) {
				Bitmap sigBitmap=wrapper.GetSigImage();
				g.DrawImage(sigBitmap,field.XPos,field.YPos-_yPosPrint,field.Width-2,field.Height-2);
				sigBitmap.Dispose();
				sigBitmap=null;
			}
			else {
				XImage sigBitmap=XImage.FromGdiPlusImage(wrapper.GetSigImage());
				gx.DrawImage(sigBitmap,p(field.XPos),p(field.YPos-_yPosPrint),p(field.Width-2),p(field.Height-2));
				sigBitmap.Dispose();
				sigBitmap=null;
			}
		}