Index: Scheduling/trunk/cs/bsdx0200GUISourceCode/Printing.cs
===================================================================
--- Scheduling/trunk/cs/bsdx0200GUISourceCode/Printing.cs	(revision 1176)
+++ Scheduling/trunk/cs/bsdx0200GUISourceCode/Printing.cs	(revision 1469)
@@ -10,5 +10,5 @@
 {
     public partial class Printing
-    { 
+    {
         /// <summary>
         /// Print Appointments
@@ -33,12 +33,12 @@
             Font f10 = new Font(FontFamily.GenericSerif, 10);
             Font f14bold = new Font(FontFamily.GenericSerif, 14, FontStyle.Bold);
-            
+
             //Center Alignment for some stuff
             StringFormat sf = new StringFormat();
             sf.Alignment = StringAlignment.Center;
-            
+
             //Header
             g.DrawString("Confidential Patient Information", f8, Brushes.Black, e.PageBounds, sf);
-            
+
             //Footer
             sf.Alignment = StringAlignment.Center;
@@ -72,5 +72,5 @@
             //resource we want to print
             dsPatientApptDisplay2.BSDXResourceRow r = ds.BSDXResource[resourceToPrint];
-            
+
             //header
             string toprint;
@@ -79,5 +79,5 @@
                 + end.ToShortDateString();
             g.DrawString(toprint, f14bold, Brushes.Black, printArea);
-            
+
             //Move print area down
             int titleHeight = (int)g.MeasureString(toprint, f14bold, printArea.Size).Height;
@@ -87,13 +87,13 @@
             //Draw Line
             g.DrawLine(new Pen(Brushes.Black, 0), printArea.X, printArea.Y, printArea.X + printArea.Width, printArea.Y);
-            
+
             //Move print area down
-            printArea.Y += 5; 
+            printArea.Y += 5;
             printArea.Height -= 5;
-            
+
             System.Data.DataRow[] appts = r.GetChildRows(ds.Relations[0]); //ds has only one relation 
 
             StringFormat sf2 = new StringFormat();                 //sf to hold tab stops
-            sf2.SetTabStops(50, new float[] { 100, 250, 25 });     
+            sf2.SetTabStops(50, new float[] { 100, 250, 25 });
 
             //appt printed starts at zero
@@ -101,6 +101,6 @@
             {
                 dsPatientApptDisplay2.PatientApptsRow a = (dsPatientApptDisplay2.PatientApptsRow)appts[apptPrinting];
-                
-                StringBuilder apptPrintStr = new StringBuilder(200); 
+
+                StringBuilder apptPrintStr = new StringBuilder(200);
                 apptPrintStr.AppendLine(a.ApptDate.ToString() + "\t" + a.Name + " (" + a.Sex + ")" + "\t" + "DOB: " + a.DOB.ToShortDateString() + "\t" + "ID: " + a.HRN);
                 apptPrintStr.AppendLine("P: " + a.HOMEPHONE + "\t" + "Address: " + a.STREET + ", " + a.CITY + ", " + a.STATE + " " + a.ZIP);
@@ -110,14 +110,14 @@
                 int printedApptHeight = (int)g.MeasureString(apptPrintStr.ToString(), f10, printArea.Width).Height;
                 if (printedApptHeight > printArea.Height) // too much to print -- move to next page
-                    // but don't increment the appointment to print since we haven't printed it yet.
-                    // i.e. apptPrinting stays the same.
+                // but don't increment the appointment to print since we haven't printed it yet.
+                // i.e. apptPrinting stays the same.
                 {
                     e.HasMorePages = true;
                     break;
                 }
-   
+
                 //otherwise print it
                 g.DrawString(apptPrintStr.ToString(), f10, Brushes.Black, printArea, sf2);
-                
+
                 //Move print area down
                 printArea.Y += printedApptHeight + 3;
@@ -148,55 +148,123 @@
         public virtual void PrintAppointmentSlip(CGAppointment appt, PrintPageEventArgs e)
         {
-            // Prep
+            // setting the reference values for calculating the needed ratio of the coming page.
+            //referrenceHeight and referrenceWidth for A6 size.
+            double referrenceHeight = 383;
+            double referrenceWidth = 213;
+
+            //check if the paper is landscape or portrait. if it is landscape then new ratio need to be calculated.
+            if (e.MarginBounds.Width > e.MarginBounds.Height)
+            {
+                //landscape = true;
+                referrenceHeight = 213;
+                referrenceWidth = 383;
+                //fontRatio = ((e.MarginBounds.Height) / referrenceHeight);
+            }
+            
+            //setting the font,width and height ratios 
+            double fontRatio = (e.MarginBounds.Height / referrenceHeight);
+            if (fontRatio > 1.0)
+            {
+                fontRatio = fontRatio * 0.75;
+            }
+            double widthRatio = ((e.MarginBounds.Width) / referrenceWidth);
+            double heightRatio = ((e.MarginBounds.Height) / referrenceHeight);
+
             Graphics g = e.Graphics;
-            Rectangle printArea = e.MarginBounds;
-            Rectangle pageArea = e.PageBounds;
+            //this is the string which is used to fill with the data and to be print on the screen. 
+            string stringData;
+
+            //in portrait we used fonts that fits with the A6 paper and changed depending on the page ratio,but in the land scape we used fonts fits with the A5 paper and counted the other pages depening on the ratios.
+            Font fontTitle = new Font(FontFamily.GenericSerif, (int)(13 * fontRatio), FontStyle.Bold); //for title
+            Font fontBody = new Font(FontFamily.GenericSerif, (int)(13 * fontRatio));
+            Font fontGroupTitle = new Font(FontFamily.GenericSansSerif, (int)(13 * fontRatio), FontStyle.Bold);
+            Font fFooter = new Font(FontFamily.GenericSerif, (int)(7 * fontRatio));
+
+            StringFormat sfCenterNear = new StringFormat()
+            {
+                Alignment = StringAlignment.Near,
+                LineAlignment = StringAlignment.Near
+            };
+
+            StringFormat sfCenterCenter = new StringFormat()
+            {
+                Alignment = StringAlignment.Center,
+                LineAlignment = StringAlignment.Center
+            };
+
+            StringFormat sfCenterFar = new StringFormat()
+            {
+                Alignment = StringAlignment.Far,
+                LineAlignment = StringAlignment.Near
+            };
+
+            StringFormat sf3 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0);
+            sf3.SetDigitSubstitution(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID, StringDigitSubstitute.Traditional);
+
+
+            //set the hard margin which different for each printer and multiplied with 2 
+            int HardMarginX = 0;
+            if ((int)(e.PageSettings.HardMarginX) > 0)
+            {
+                HardMarginX=((int)(e.PageSettings.HardMarginX) *2);
+            }
+            int HardMarginY = 0;
+            if ((int)(e.PageSettings.HardMarginY) > 0)
+            {
+                HardMarginY = ((int)(e.PageSettings.HardMarginY) * 2);
+            }
+
+            // Draw Header 
+
+            string division = CGDocumentManager.Current.ConnectInfo.DivisionName;
+            int divisionStringHeight = (int)g.MeasureString(division.ToString(), fontBody, e.PageBounds.Width - (int)(10 * widthRatio) - HardMarginX).Height;
+            
             Rectangle headerArea = new Rectangle()
             {
-                X = e.MarginBounds.X,
-                Y = e.PageBounds.Y,
-                Height = e.MarginBounds.Y - e.PageBounds.Y - 50,
-                Width = e.MarginBounds.Width
-            };
+                X = (int)(5 * widthRatio),
+                Y = (int)(5 * heightRatio),
+                Height = divisionStringHeight + (int)(5 * heightRatio),
+                Width = e.PageBounds.Width - (int)(10 * widthRatio) - HardMarginX
+            };
+            g.DrawString(division, fontBody, Brushes.Black, headerArea, sfCenterNear);
+
+            //use stringData to print the footer (center all the way)
+            stringData = strings.Printed + ": " + DateTime.Now.ToString();
+            int stringDataStringHeight = (int)g.MeasureString(stringData.ToString(), fFooter, e.MarginBounds.Width).Height;
             Rectangle footerArea = new Rectangle()
             {
-                X = e.MarginBounds.X,
-                Y = e.MarginBounds.Height + headerArea.Height,
-                Width = e.MarginBounds.Width,
-                Height = pageArea.Height - (e.MarginBounds.Height + headerArea.Height)
-            };
-
-            string s;
-
-            // A few fonts
-            Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
-            Font fBody = new Font(FontFamily.GenericSerif, 12);
-            Font fGroupTitle = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
-
-            StringFormat sfCenterCenter = new StringFormat()
-            {
-                 Alignment = StringAlignment.Center,
-                 LineAlignment = StringAlignment.Center
-            };
-            
-            // Draw Header
-            string division = CGDocumentManager.Current.ConnectInfo.DivisionName;
-            g.DrawString(division, fBody, Brushes.Black, headerArea, sfCenterCenter);
-
-            const int watermarkLength = 75;
+                X = headerArea.X,
+                Y = e.PageBounds.Height - stringDataStringHeight - HardMarginY - (int)(5 * heightRatio),
+                Width = headerArea.Width,
+                Height = stringDataStringHeight
+            };
+            g.DrawString(stringData, fFooter, Brushes.Black, footerArea, sfCenterCenter);
+            
+            //setting the printing area bigger than the margin bounds to use more printing space on the paper.
+            Rectangle printArea = new Rectangle()
+            {
+                X = headerArea.X,
+                Y = headerArea.Y+headerArea.Height,
+                Height = footerArea.Y-(headerArea.Y+headerArea.Height) - (int)(5 * heightRatio),
+                Width = headerArea.Width
+            };
+            
+            //  if there is a need for the watermark use the following code.
+            //const int watermarkLength = 75*heightratio;
 
             // Move down for optional form paper
-            printArea.Y += watermarkLength;
-            printArea.Height -= watermarkLength;
-
-            // Draw Title
-            StringFormat sfCenter = new StringFormat();
-            sfCenter.Alignment = StringAlignment.Center; //for title & header
-
-            s = strings.ApptReminderSlip;
-            g.DrawString(s, fTitle, Brushes.Black, printArea, sfCenter); //title
-
-            // move down
-            int titleHeight = (int)g.MeasureString(s, fTitle, printArea.Width).Height;
+            //printArea.Y += watermarkLength;
+            //printArea.Height -= watermarkLength;
+
+            //// Draw Title
+            //StringFormat sfCenter = new StringFormat();
+            //sfCenter.Alignment = StringAlignment.Center; //for title & header
+
+            //string data for the appointment slip title
+            stringData = strings.ApptReminderSlip;
+            g.DrawString(stringData, fontTitle, Brushes.Black, printArea, sfCenterFar); //title
+            
+            //// move down
+            int titleHeight = (int)g.MeasureString(stringData, fontTitle, printArea.Width).Height;
             printArea.Y += titleHeight;
             printArea.Height -= titleHeight;
@@ -204,92 +272,89 @@
             // draw underline
             g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
-            printArea.Y += 15;
-            printArea.Height -= 15;
-
-            // draw curved rectangle.
-            Rectangle personalInfoRectangle = new Rectangle(e.MarginBounds.X, printArea.Y + 30, 280, 300);
-            using (GraphicsPath path = GetRoundedRectPath(personalInfoRectangle, 10))
+            printArea.Y += (int)(10 * heightRatio);
+            printArea.Height -= (int)(10 * heightRatio);
+
+            // building the string of the person information to write
+            StringBuilder personInformationString = new StringBuilder(500);
+            personInformationString.AppendLine(strings.Name + ":" + "\t" + appt.Patient.Name);
+            //personInformationString.AppendLine();
+            stringData = appt.Patient.Sex == Sex.Male ? strings.Male : strings.Female;
+            personInformationString.AppendLine(strings.ID + ":" + "\t" + appt.Patient.ID + "\t" + "( " + stringData + " )");
+            //personInformationString.AppendLine();
+            stringData = appt.Patient.DOB.ToString("dd") + " " + appt.Patient.DOB.ToString("MMM") + ", " + appt.Patient.DOB.Year;
+            personInformationString.AppendLine(strings.DOB + ":" + "\t" + stringData);
+            //personInformationString.AppendLine();
+            //personInformationString.AppendLine(strings.Age + ":" + "\t" + appt.Patient.UserFriendlyAge);
+
+
+            // building the string of the appointment information to write
+            StringBuilder appointmentInformationString = new StringBuilder(500);
+            appointmentInformationString = new StringBuilder();
+            appointmentInformationString.AppendLine(strings.Clinic + ":" + "\t" + appt.Resource);
+            //appointmentInformationString.AppendLine();
+            stringData = appt.StartTime.ToString("dddd") + " " + appt.StartTime.ToString("dd") + " " + appt.StartTime.ToString("MMM") + ", " + appt.StartTime.Year;
+            appointmentInformationString.AppendLine(strings.Date + ":" + "\t" + stringData);
+            //sb.AppendLine();
+            //appointmentInformationString.AppendLine(strings.Day + ":" + "\t" + appt.StartTime.ToString("dddd"));
+            //sb.AppendLine();
+            appointmentInformationString.AppendLine(strings.Time + ":" + "\t" + appt.StartTime.ToShortTimeString());
+
+
+            //counting the width and hieght of the information inner aera for the person and appointment rectangels.
+            int InfoInnerRectangleWidth = (printArea.Width / 2 - printArea.X / 2) - (int)(10 * widthRatio);
+
+            //Counting the height of the two strings (PersontInformationStringappointment & InformationStringto)to be allocated to the InfoInnerRectangleHeight later.
+            int PersonInformationStringHeight = (int)g.MeasureString(personInformationString.ToString(), fontBody, InfoInnerRectangleWidth).Height;
+            int appointmentInformationStringHeight = (int)g.MeasureString(appointmentInformationString.ToString(), fontBody, InfoInnerRectangleWidth).Height;
+            
+            int InfoInnerRectangleHeight = PersonInformationStringHeight;
+            if (appointmentInformationStringHeight > PersonInformationStringHeight)
+            {
+                InfoInnerRectangleHeight = appointmentInformationStringHeight;
+            }
+
+            // draw curved rectangle for the person informations.
+            Rectangle personalInfoRectangle = new Rectangle(printArea.X, printArea.Y, InfoInnerRectangleWidth + (int)(10 * widthRatio), InfoInnerRectangleHeight + (int)(10 * heightRatio));
+            using (GraphicsPath path = GetRoundedRectPath(personalInfoRectangle, 5))
             {
                 g.DrawPath(Pens.Black, path);
             }
-
-            // group header
-            s = strings.PtInfo;
-            StringFormat sf3 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0);
-            g.DrawString(s, fGroupTitle, Brushes.Black, new Rectangle(personalInfoRectangle.X, personalInfoRectangle.Y - 20,personalInfoRectangle.Width, 20),sf3);
             
             // inner rectangle for drawing strings:
-            Rectangle personalInfoInnerRectangle = new Rectangle(personalInfoRectangle.X + 20, personalInfoRectangle.Y + 20, 280 - 40, 300 - 40);
-            
-            // Strings to write
-            StringBuilder sb = new StringBuilder(500);
-            sb.AppendLine(strings.Name + ":" + "\t" + appt.Patient.Name);
-            sb.AppendLine();
-            sb.AppendLine(strings.ID + ":" + "\t" + appt.Patient.ID);
-            sb.AppendLine();
-            s = appt.Patient.DOB.ToString("dd") + " " + appt.Patient.DOB.ToString("MMM") + ", " + appt.Patient.DOB.Year;
-            sb.AppendLine(strings.DOB + ":" + "\t" + s);
-            sb.AppendLine();
-            sb.AppendLine(strings.Age + ":" + "\t" + appt.Patient.UserFriendlyAge);
-            sb.AppendLine();
-            s = appt.Patient.Sex == Sex.Male ? strings.Male : strings.Female;
-            sb.AppendLine(strings.Sex + ":" + "\t" + s);
-
-            // Draw them
-            sf3 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0);
-            sf3.SetTabStops(0, new float[] {75} );
-            sf3.SetDigitSubstitution(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID, StringDigitSubstitute.Traditional);
-            g.DrawString(sb.ToString(), fBody, Brushes.Black, personalInfoInnerRectangle, sf3);
-
-            // draw curved rectangle
-            Rectangle apptInfoRectangle = new Rectangle(e.MarginBounds.X + e.MarginBounds.Width - 280, printArea.Y + 30, 280, 300);
-            using (GraphicsPath path = GetRoundedRectPath(apptInfoRectangle, 10))
+            Rectangle personalInfoInnerRectangle = new Rectangle(personalInfoRectangle.X + (int)(5 * widthRatio), personalInfoRectangle.Y + (int)(5 * heightRatio), InfoInnerRectangleWidth, InfoInnerRectangleHeight);
+
+            // Draw the preson informations.
+            //sf3.SetTabStops(0, new float[] {75} );
+            
+            g.DrawString(personInformationString.ToString(), fontBody, Brushes.Black, personalInfoInnerRectangle, sf3);
+
+            // draw curved rectangle for the appointment informations.
+            Rectangle apptInfoRectangle = new Rectangle((int)(printArea.X + personalInfoRectangle.Width + printArea.X), personalInfoRectangle.Y, personalInfoRectangle.Width, personalInfoRectangle.Height);
+            using (GraphicsPath path = GetRoundedRectPath(apptInfoRectangle, 5))
             {
                 g.DrawPath(Pens.Black, path);
             }
 
-            s = strings.ApptInfo;
-            // group header
-            g.DrawString(s, fGroupTitle, Brushes.Black, new Rectangle(apptInfoRectangle.X, apptInfoRectangle.Y - 20,apptInfoRectangle.Width, 20), sf3);
-
-            // Strings to write
-            sb = new StringBuilder();
-            sb.AppendLine(strings.Clinic + ":" + "\t" + appt.Resource);
-            sb.AppendLine();
-            s = appt.StartTime.ToString("dd") + " " + appt.StartTime.ToString("MMM") + ", " + appt.StartTime.Year;
-            sb.AppendLine(strings.Date + ":" + "\t" + s);
-            sb.AppendLine();
-            sb.AppendLine(strings.Day + ":" + "\t" + appt.StartTime.ToString("dddd"));
-            sb.AppendLine();
-            sb.AppendLine(strings.Time + ":" + "\t" + appt.StartTime.ToShortTimeString());
-
-            // Draw them
-            Rectangle apptInfoInnerRectangle = new Rectangle(apptInfoRectangle.X + 20, apptInfoRectangle.Y + 20, 280 - 40, 300 - 40);
-
-            // Draw them
-            g.DrawString(sb.ToString(), fBody, Brushes.Black, apptInfoInnerRectangle, sf3);
+
+            // Draw appointment informations in the inner rectangle.
+            Rectangle apptInfoInnerRectangle = new Rectangle(apptInfoRectangle.X + (int)(5 * widthRatio), apptInfoRectangle.Y + (int)(5 * heightRatio), InfoInnerRectangleWidth, InfoInnerRectangleHeight);
+            g.DrawString(appointmentInformationString.ToString(), fontBody, Brushes.Black, apptInfoInnerRectangle, sf3);
 
             // Move Drawing Rectangle Down
-            printArea.Y += 300 + 30 + 20;
-            printArea.Height -= 300 + 30 + 20;
+            printArea.Y += personalInfoRectangle.Height  + (int)(5 * heightRatio);
+            printArea.Height -= personalInfoRectangle.Height +  (int)(5 * heightRatio);
 
             // Draw New Line
             g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
-            printArea.Y += 5;
-            printArea.Height -= 5;
+            printArea.Y += (int)(5 * heightRatio);
+            printArea.Height -= (int)(5 * heightRatio);
 
             // Draw new Title
-            s = strings.ClinicInstructions;
-            g.DrawString(s, fTitle, Brushes.Black, printArea, sfCenter); //title
-
+            stringData = strings.ClinicInstructions;
+            titleHeight = (int)g.MeasureString(stringData, fontTitle, printArea.Width).Height;
+            g.DrawString(stringData, fontTitle, Brushes.Black, printArea, sf3); //title
             // move down
-            titleHeight = (int)g.MeasureString(s, fTitle, printArea.Width).Height;
             printArea.Y += titleHeight;
             printArea.Height -= titleHeight;
-
-            // Draw New Line
-            g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
-            printArea.Y += 15;
-            printArea.Height -= 15;
 
             // Get Resource Clinic Appointment Letter Text
@@ -301,40 +366,56 @@
 
             if (String.IsNullOrWhiteSpace(ltrTxt)) ltrTxt = strings.NoInstructionsProvided;
-
-            g.DrawString(ltrTxt, fBody, Brushes.Black, printArea, sf3);
-
-            int ltrTxtHeight = (int)g.MeasureString(ltrTxt, fBody).Height;
-
-            printArea.Y += ltrTxtHeight + 15;
-            printArea.Height -= ltrTxtHeight + 15;
-
-            g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
-            printArea.Y += 5;
-            printArea.Height -= 5;
-
-            s = strings.Notes;
-            g.DrawString(s, fTitle, Brushes.Black, printArea, sfCenter); // Notes title
-            
-            // move down
-            titleHeight = (int)g.MeasureString(s, fTitle, printArea.Width).Height;
-            printArea.Y += titleHeight;
-            printArea.Height -= titleHeight;
-
-            // Draw New Line
-            g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
-            printArea.Y += 15;
-            printArea.Height -= 15;
-
-            // Draw Notes Area
-            using (GraphicsPath path = GetRoundedRectPath(printArea, 15))
-            {
-                g.DrawPath(Pens.Black, path);
-            }
-
-            //use sf0 to print the footer (center all the way)
-            s = strings.Printed + ": " + DateTime.Now.ToString();
-            Font fFooter = new Font(FontFamily.GenericSerif, 7);
-            g.DrawString(s, fFooter, Brushes.Black, footerArea, sfCenterCenter);
-
+            int ltrTxtHeight = (int)g.MeasureString(ltrTxt, fontBody,printArea.Width).Height;
+            //setting the instructions area smaller than the printing area.
+            int instructionsAreaHeight = ltrTxtHeight;
+            //missingString true if there are no more printing area for the instructions and will use it to print a statement for it.
+            bool missingString = false;
+            string missingStringStatement = "";
+            int missingStringStatementHeight = 0;
+            if (ltrTxtHeight > printArea.Height)
+            {
+                missingStringStatement = "etc...";
+                missingStringStatementHeight = (int)g.MeasureString(missingStringStatement, fFooter, printArea.Width).Height;
+                instructionsAreaHeight = printArea.Height -missingStringStatementHeight- (int)(5 * heightRatio);
+                missingString = true;
+            }
+            Rectangle instructionsArea = new Rectangle()
+            {
+                X = printArea.X,
+                Y = printArea.Y,
+                Height = instructionsAreaHeight,
+                Width = printArea.Width
+            };
+            g.DrawString(ltrTxt, fontBody, Brushes.Black, instructionsArea, sf3);
+            
+            //moving down
+            printArea.Y += instructionsAreaHeight + (int)(5 * heightRatio);
+            printArea.Height -= instructionsAreaHeight + (int)(5 * heightRatio);
+
+            if (missingString)
+            {
+                g.DrawString(missingStringStatement, fFooter, Brushes.Black, printArea, sf3); //title
+                printArea.Y += missingStringStatementHeight;
+                printArea.Height -= missingStringStatementHeight;
+            }
+            //Draing new line
+            if (printArea.Height > 0)
+            {
+                g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
+                printArea.Y += (int)(5 * heightRatio);
+                printArea.Height -= (int)(5 * heightRatio);
+
+                string noteStringData = strings.Notes;
+                int noteTitleHeight = (int)g.MeasureString(noteStringData, fontTitle, printArea.Width).Height;
+
+                //check if the remaining area height enugh for the notes 
+                if (printArea.Height > ((int)(noteTitleHeight)))
+                {
+                    //draw the note title.
+                    g.DrawString(noteStringData, fontTitle, Brushes.Black, printArea, sf3); // Notes title
+                }
+            
+
+            }
             g.Dispose();
         }
@@ -344,8 +425,8 @@
         {
             int diameter = 2 * radius;
-           
+
             Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter));
             GraphicsPath path = new GraphicsPath();
-            
+
             path.AddArc(arcRect, 180, 90); //top left
             arcRect.X = rect.Right - diameter;
@@ -383,5 +464,5 @@
             printArea.Y += titleHeight;
             printArea.Height -= titleHeight;
-            
+
             // draw underline
             g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
@@ -419,5 +500,5 @@
             g.Dispose();
         }
-       
+
         /// <summary>
         /// Cancellation Letter to be given or mailed to the patient
@@ -460,5 +541,5 @@
             if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft)
                 sf2.FormatFlags = StringFormatFlags.DirectionRightToLeft;
-            
+
             // write missive
             g.DrawString(letter, fBody, Brushes.Black, printArea, sf2);
@@ -558,32 +639,38 @@
         public virtual void PrintRoutingSlip(CGAppointment appt, int apptOrder, PrintPageEventArgs e)
         {
-            // Prep
+            // setting the reference values for calculating the needed ratio of the coming page.
+            //referrenceHeight and referrenceWidth for A6 size.
+            double referrenceHeight = 383;
+            double referrenceWidth = 213;
+
+            //check if the paper is landscape or portrait. if it is landscape then new ratio need to be calculated.
+            if (e.MarginBounds.Width > e.MarginBounds.Height)
+            {
+                //landscape = true;
+                referrenceHeight = 213;
+                referrenceWidth = 383;
+                //fontRatio = ((e.MarginBounds.Height) / referrenceHeight);
+            }
+
+            //setting the font,width and height ratios 
+            double fontRatio = (e.MarginBounds.Height / referrenceHeight);
+            if (fontRatio > 1.0)
+            {
+                fontRatio = fontRatio * 0.75;
+            }
+            double widthRatio = ((e.MarginBounds.Width) / referrenceWidth);
+            double heightRatio = ((e.MarginBounds.Height) / referrenceHeight);
+
             Graphics g = e.Graphics;
-            Rectangle printArea = e.MarginBounds;
-            Rectangle pageArea = e.PageBounds;
-            Rectangle headerArea = new Rectangle()
-            {
-                X = e.MarginBounds.X, 
-                Y = e.PageBounds.Y,  //0
-                Height = e.MarginBounds.Y - e.PageBounds.Y - 50, //100px - 50px
-                Width = e.MarginBounds.Width
-            };
-            Rectangle footerArea = new Rectangle()
-            {
-                X = e.MarginBounds.X,
-                Y = e.MarginBounds.Height + headerArea.Height,
-                Width = e.MarginBounds.Width,
-                Height = pageArea.Height - (e.MarginBounds.Height + headerArea.Height)
-            };
-
-            const int part1Height = 400;
-            string s;
-
-            // A few fonts
-            Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
-            Font fBody = new Font(FontFamily.GenericSerif, 12);
-            Font fGroupTitle = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
-
-            StringFormat sf0 = new StringFormat()
+            //this is the string which is used to fill with the data and to be print on the screen. 
+            string stringData;
+
+            //in portrait we used fonts that fits with the A6 paper and changed depending on the page ratio,but in the land scape we used fonts fits with the A5 paper and counted the other pages depening on the ratios.
+            Font fontTitle = new Font(FontFamily.GenericSerif, (int)(13 * fontRatio), FontStyle.Bold); //for title
+            Font fontBody = new Font(FontFamily.GenericSerif, (int)(13 * fontRatio));
+            Font fontGroupTitle = new Font(FontFamily.GenericSansSerif, (int)(13 * fontRatio), FontStyle.Bold);
+            Font fFooter = new Font(FontFamily.GenericSerif, (int)(7 * fontRatio));
+
+            StringFormat sfCenterCenter = new StringFormat()
             {
                 Alignment = StringAlignment.Center,
@@ -591,22 +678,68 @@
             };
 
+            //set the hard margin which different for each printer and multiplied with 2 
+            int HardMarginX = 0;
+            if ((int)(e.PageSettings.HardMarginX) > 0)
+            {
+                HardMarginX = ((int)(e.PageSettings.HardMarginX) * 2);
+            }
+            int HardMarginY = 0;
+            if ((int)(e.PageSettings.HardMarginY) > 0)
+            {
+                HardMarginY = ((int)(e.PageSettings.HardMarginY) * 2);
+            }
+
             // Draw Header
             string division = CGDocumentManager.Current.ConnectInfo.DivisionName;
-            g.DrawString(division, fBody, Brushes.Black, headerArea, sf0);
-
-            const int watermarkLength = 75;
+            int divisionStringHeight = (int)g.MeasureString(division.ToString(), fontBody, e.MarginBounds.Width).Height;
+            Rectangle headerArea = new Rectangle()
+            {
+                X = (int)(5 * widthRatio),
+                Y = (int)(5 * heightRatio),
+                Height = divisionStringHeight + (int)(5 * heightRatio),
+                Width = e.PageBounds.Width - (int)(10 * widthRatio) - HardMarginX
+            };
+            g.DrawString(division, fontBody, Brushes.Black, headerArea, sfCenterCenter);
+
+
+            //use stringData to print the footer (center all the way)
+            stringData = strings.Printed + ": " + DateTime.Now.ToString();
+            int stringDataStringHeight = (int)g.MeasureString(stringData.ToString(), fFooter, e.MarginBounds.Width).Height;
+            Rectangle footerArea = new Rectangle()
+            {
+                X = headerArea.X,
+                Y = e.PageBounds.Height - stringDataStringHeight - HardMarginY - (int)(5 * heightRatio),
+                Width = headerArea.Width,
+                Height = stringDataStringHeight
+            };
+            g.DrawString(stringData, fFooter, Brushes.Black, footerArea, sfCenterCenter);
+
+
+
+            //setting the printing area bigger than the margin bounds to use more printing space on the paper.
+            Rectangle printArea = new Rectangle()
+            {
+                X = headerArea.X,
+                Y = headerArea.Y + headerArea.Height,
+                Height = footerArea.Y - (headerArea.Y + headerArea.Height) - (int)(5 * heightRatio),
+                Width = headerArea.Width
+            };
+
+
+            //  if there is a need for the watermark use the following code.
+            //const int watermarkLength = 75*heightratio;
 
             // Move down for optional form paper
-            printArea.Y += watermarkLength;
-            printArea.Height -= watermarkLength;
+            //printArea.Y += watermarkLength;
+            //printArea.Height -= watermarkLength;
 
             // Draw Title
-            StringFormat sf = new StringFormat();
-            sf.Alignment = StringAlignment.Center; //for title & header
+            StringFormat sfCenter = new StringFormat();
+            sfCenter.Alignment = StringAlignment.Center; //for title & header
             string title = strings.RoutingSlip;
-            g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
+            g.DrawString(title, fontTitle, Brushes.Black, printArea, sfCenter); //title
 
             // move down
-            int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
+            int titleHeight = (int)g.MeasureString(title, fontTitle, printArea.Width).Height;
             printArea.Y += titleHeight;
             printArea.Height -= titleHeight;
@@ -614,76 +747,92 @@
             // draw underline
             g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
-            printArea.Y += 15;
-            printArea.Height -= 15;
-
-            // draw curved rectangle.
-            Rectangle personalInfoRectangle = new Rectangle(e.MarginBounds.X, printArea.Y + 30, 280, part1Height);
-            using (GraphicsPath path = GetRoundedRectPath(personalInfoRectangle, 10))
+            printArea.Y += (int)(5 * heightRatio);
+            printArea.Height -= (int)(5 * heightRatio);
+
+            // Strings to write
+
+            StringBuilder personInformationString = new StringBuilder(500);
+            personInformationString.AppendLine(strings.Name + ":" + "\t" + appt.Patient.Name);
+            //personInformationString.AppendLine();
+            personInformationString.AppendLine(strings.ID + ":" + "\t" + appt.Patient.ID);
+            //personInformationString.AppendLine();
+            stringData = appt.Patient.DOB.ToString("dd") + " " + appt.Patient.DOB.ToString("MMM") + ", " + appt.Patient.DOB.Year;
+            personInformationString.AppendLine(strings.DOB + ":" + "\t" + stringData);
+            //personInformationString.AppendLine();
+            personInformationString.AppendLine(strings.Age + ":" + "\t" + appt.Patient.UserFriendlyAge);
+            //personInformationString.AppendLine();
+            //personInformationString.AppendLine("Sex:" + "\t" + appt.Patient.Sex.ToString());
+
+            // Strings to write
+            StringBuilder appointmentInformationString = new StringBuilder();
+            appointmentInformationString.AppendLine(strings.Clinic + ":");
+            appointmentInformationString.AppendLine(appt.Resource);
+            //appointmentInformationString.AppendLine();
+            appointmentInformationString.AppendLine(strings.AppointmentProvider + ":");
+            appointmentInformationString.AppendLine((appt.Provider == null) ? strings.none : appt.Provider.ToString());  //Appt Provider or (none) if null
+            //appointmentInformationString.AppendLine();
+            appointmentInformationString.AppendLine(strings.PatientOrder + ":" + "\t" + apptOrder);
+            appointmentInformationString.AppendLine(strings.Date + ":" + "\t" + appt.StartTime.ToShortDateString() + " " + appt.StartTime.ToShortTimeString());
+            //appointmentInformationString.AppendLine();
+            appointmentInformationString.AppendLine(strings.AppointmentNote + ":");
+            appointmentInformationString.AppendLine(String.IsNullOrWhiteSpace(appt.Note) ? strings.none : appt.Note);
+            
+            //counting the width and hieght of the information inner aera for the person and appointment rectangels.
+            int InfoInnerRectangleWidth = (printArea.Width / 2 - printArea.X / 2) - (int)(10 * widthRatio);
+
+            //Counting the height of the two strings (PersontInformationStringappointment & InformationStringto)to be allocated to the InfoInnerRectangleHeight later.
+            int PersonInformationStringHeight = (int)g.MeasureString(personInformationString.ToString(), fontBody, InfoInnerRectangleWidth).Height;
+            int appointmentInformationStringHeight = (int)g.MeasureString(appointmentInformationString.ToString(), fontBody, InfoInnerRectangleWidth).Height;
+
+            int InfoInnerRectangleHeight = PersonInformationStringHeight;
+            if (appointmentInformationStringHeight > PersonInformationStringHeight)
+            {
+                InfoInnerRectangleHeight = appointmentInformationStringHeight;
+            }
+
+            // group header for the person informations.
+            stringData = strings.PtInfo;
+            StringFormat sf3 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0);
+            stringDataStringHeight = (int)g.MeasureString(stringData.ToString(), fontGroupTitle, InfoInnerRectangleWidth).Height;
+            g.DrawString(stringData, fontGroupTitle, Brushes.Black, new Rectangle(printArea.X, printArea.Y, InfoInnerRectangleWidth, stringDataStringHeight), sf3);
+
+            // group header for the appointment information
+            stringData = strings.ApptInfo;
+            g.DrawString(stringData, fontGroupTitle, Brushes.Black, new Rectangle((int)(printArea.X + (InfoInnerRectangleWidth + (int)(10 * widthRatio)) + printArea.X), printArea.Y, InfoInnerRectangleWidth, stringDataStringHeight), sf3);
+
+            //moving down
+            printArea.Y += stringDataStringHeight + (int)(5 * heightRatio);
+            printArea.Height -= stringDataStringHeight + (int)(5 * heightRatio);
+
+            // draw curved rectangle for the person informations.
+            Rectangle personalInfoRectangle = new Rectangle(printArea.X, printArea.Y, InfoInnerRectangleWidth + (int)(10 * widthRatio), InfoInnerRectangleHeight + (int)(10 * heightRatio));
+            using (GraphicsPath path = GetRoundedRectPath(personalInfoRectangle, 5))
             {
                 g.DrawPath(Pens.Black, path);
             }
 
-            // group header
-            s = strings.PtInfo;
-            StringFormat sf3 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0);
-            g.DrawString(s, fGroupTitle, Brushes.Black, new Rectangle(personalInfoRectangle.X, personalInfoRectangle.Y - 20, personalInfoRectangle.Width, 20), sf3);
-
-            StringFormat sf4 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0);
-            sf4.SetTabStops(0, new float[] { 75 });
-            sf4.SetDigitSubstitution(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID, StringDigitSubstitute.Traditional);
-
             // inner rectangle for drawing strings:
-            Rectangle personalInfoInnerRectangle = new Rectangle(personalInfoRectangle.X + 20, personalInfoRectangle.Y + 20, personalInfoRectangle.Width - 40, personalInfoRectangle.Height - 40);
-
-            // Strings to write
-            StringBuilder sb = new StringBuilder(500);
-            sb.AppendLine(strings.Name + ":" + "\t" + appt.Patient.Name);
-            sb.AppendLine();
-            sb.AppendLine(strings.ID + ":" + "\t" + appt.Patient.ID);
-            sb.AppendLine();
-            s = appt.Patient.DOB.ToString("dd") + " " + appt.Patient.DOB.ToString("MMM") + ", " + appt.Patient.DOB.Year;
-            sb.AppendLine(strings.DOB + ":" + "\t" + s);
-            sb.AppendLine();
-            sb.AppendLine(strings.Age + ":" + "\t" + appt.Patient.UserFriendlyAge);
-            //sb.AppendLine();
-            //sb.AppendLine("Sex:" + "\t" + appt.Patient.Sex.ToString());
-
-            // Draw them
-            g.DrawString(sb.ToString(), fBody, Brushes.Black, personalInfoInnerRectangle, sf4);
-
-            // draw curved rectangle
-            Rectangle apptInfoRectangle = new Rectangle(e.MarginBounds.X + e.MarginBounds.Width - 280, printArea.Y + 30, 280, part1Height);
-            using (GraphicsPath path = GetRoundedRectPath(apptInfoRectangle, 10))
+            Rectangle personalInfoInnerRectangle = new Rectangle(personalInfoRectangle.X + (int)(5 * widthRatio), personalInfoRectangle.Y + (int)(5 * heightRatio), InfoInnerRectangleWidth, InfoInnerRectangleHeight);
+
+            // Draw the preson informations.
+            sf3 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0);
+            //sf3.SetTabStops(0, new float[] {75} );
+            sf3.SetDigitSubstitution(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID, StringDigitSubstitute.Traditional);
+            g.DrawString(personInformationString.ToString(), fontBody, Brushes.Black, personalInfoInnerRectangle, sf3);
+
+            // draw curved rectangle for the appointment informations.
+            Rectangle apptInfoRectangle = new Rectangle((int)(printArea.X + personalInfoRectangle.Width + printArea.X), personalInfoRectangle.Y, personalInfoRectangle.Width, personalInfoRectangle.Height);
+            using (GraphicsPath path = GetRoundedRectPath(apptInfoRectangle, 5))
             {
                 g.DrawPath(Pens.Black, path);
             }
 
-            // group header
-            s = strings.ApptInfo;
-            g.DrawString(s, fGroupTitle, Brushes.Black, new Rectangle(apptInfoRectangle.X, apptInfoRectangle.Y - 20, apptInfoRectangle.Width, 20), sf3);
-
-            // Strings to write
-            sb = new StringBuilder();
-            sb.AppendLine(strings.Clinic + ":");
-            sb.AppendLine(appt.Resource);
-            sb.AppendLine();
-            sb.AppendLine(strings.AppointmentProvider + ":"); 
-            sb.AppendLine((appt.Provider == null) ? strings.none : appt.Provider.ToString());  //Appt Provider or (none) if null
-            sb.AppendLine();
-            sb.AppendLine(strings.PatientOrder + ":" + "\t" + apptOrder);
-            sb.AppendLine(strings.Date + ":" + "\t" + appt.StartTime.ToShortDateString() + " " + appt.StartTime.ToShortTimeString());
-            sb.AppendLine();
-            sb.AppendLine(strings.AppointmentNote + ":");
-            sb.AppendLine(String.IsNullOrWhiteSpace(appt.Note)? strings.none : appt.Note);
-
-            // Draw them
-            Rectangle apptInfoInnerRectangle = new Rectangle(apptInfoRectangle.X + 20, apptInfoRectangle.Y + 20, apptInfoRectangle.Width - 40, apptInfoRectangle.Height - 40);
-
-            // Draw them
-            g.DrawString(sb.ToString(), fBody, Brushes.Black, apptInfoInnerRectangle, sf4);
-
+            // Draw appointment informations in the inner rectangle.
+            Rectangle apptInfoInnerRectangle = new Rectangle(apptInfoRectangle.X + (int)(5 * widthRatio), apptInfoRectangle.Y + (int)(5 * heightRatio), InfoInnerRectangleWidth, InfoInnerRectangleHeight);
+            g.DrawString(appointmentInformationString.ToString(), fontBody, Brushes.Black, apptInfoInnerRectangle, sf3);
+            
             // Move Drawing Rectangle Down
-            printArea.Y += apptInfoRectangle.Height + 30 + 20;
-            printArea.Height -= apptInfoRectangle.Height + 30 + 20;
+            printArea.Y += personalInfoRectangle.Height +  (int)(5 * heightRatio);
+            printArea.Height -= personalInfoRectangle.Height + (int)(5 * heightRatio);
 
             // Draw New Line
@@ -694,10 +843,10 @@
             }
 
-            printArea.Y += 5;
-            printArea.Height -= 5;
-
-            s = strings.ScratchArea;
-            g.DrawString(s, fGroupTitle, Brushes.Black, printArea, sf3); 
-            
+            printArea.Y += (int)(5 * heightRatio);
+            printArea.Height -= (int)(5 * heightRatio);
+
+            stringData = strings.ScratchArea;
+            g.DrawString(stringData, fontGroupTitle, Brushes.Black, printArea, sf3);
+
             /* Per Al-Najjar, we don't want the next appointment instructions section
             // move down
@@ -714,13 +863,7 @@
             printArea.Height -= 5;
 
-            s = strings.NextAppointmentInstructions;
-            g.DrawString(s, fGroupTitle, Brushes.Black, printArea, sf3);
+            stringData = strings.NextAppointmentInstructions;
+            g.DrawString(stringData, fontGroupTitle, Brushes.Black, printArea, sf3);
             */
-
-            // Draw Footer
-            //use sf0 to print the footer (center all the way)
-            s = strings.Printed + ": " + DateTime.Now.ToString();
-            Font fFooter = new Font(FontFamily.GenericSerif, 7);
-            g.DrawString(s, fFooter, Brushes.Black, footerArea, sf0);
 
             g.Dispose();
