Exemplo n.º 1
0
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Graphics g    = e.Graphics;
            Pen      aPen = new Pen(Brushes.Black, 1);

            e.PageSettings.PaperSize = new System.Drawing.Printing.PaperSize("A4", 1100, 850);
            //e.PageSettings.
            Font font1  = new Font("Times New Roman", 12.25f, FontStyle.Underline | FontStyle.Bold);
            Font font11 = new Font("Times New Roman", 12.25f, FontStyle.Bold);
            Font font2  = new Font("Times New Roman", 12.25f, FontStyle.Bold);
            Font font4  = new Font("Times New Roman", 12.0f, FontStyle.Bold);
            Font font41 = new Font("Times New Roman", 12.0f);
            Font font3  = new Font("Courier New", 8.25f);
            Font font31 = new Font("Courier New", 12.5f, FontStyle.Bold);
            Font font5  = new Font("Times New Roman", 6.0f, FontStyle.Italic);

            float font1Hght = font1.Height;
            float font2Hght = font2.Height;
            float font3Hght = font3.Height;
            float font4Hght = font4.Height;
            float font5Hght = font5.Height;

            float pageWidth  = e.PageSettings.PaperSize.Width - 40;  //e.PageSettings.PrintableArea.Width;
            float pageHeight = e.PageSettings.PaperSize.Height - 40; // e.PageSettings.PrintableArea.Height;
            float txtwdth    = 0;
            //cmnCde.showMsg(pageWidth.ToString(), 0);
            float startX  = 40;
            float startY  = 40;
            float offsetY = 0;
            float ght     = 0;

            //StringBuilder strPrnt = new StringBuilder();
            //strPrnt.AppendLine("Received From");
            string[] nwLn;

            if (this.pageNo == 1)
            { //Org Logo
              //RectangleF srcRect = new Rectangle(0, 0, this.BackgroundImage.Width,
              //BackgroundImage.Height);
              //RectangleF destRect = new Rectangle(0, 0, nWidth, nHeight);
              //Rectangle destRect = new Rectangle(0, 0, nWidth, nHeight);
                Image img     = cmnCde.getDBImageFile(cmnCde.Org_id.ToString() + ".png", 0);
                float picWdth = 100.00F;
                float picHght = (float)(picWdth / img.Width) * (float)img.Height;

                g.DrawImage(img, startX, startY + offsetY, picWdth, picHght);
                //g.DrawImage(this.LargerImage, destRect, srcRect, GraphicsUnit.Pixel);

                //Org Name
                nwLn = cmnCde.breakRptTxtDown(
                    cmnCde.getOrgName(cmnCde.Org_id),
                    pageWidth + 85, font2, g);
                for (int i = 0; i < nwLn.Length; i++)
                {
                    g.DrawString(nwLn[i]
                                 , font2, Brushes.Black, startX + picWdth, startY + offsetY);
                    offsetY += font2Hght;
                }

                //Pstal Address
                g.DrawString(cmnCde.getOrgPstlAddrs(cmnCde.Org_id).Trim(),
                             font2, Brushes.Black, startX + picWdth, startY + offsetY);
                //offsetY += font2Hght;
                ght = g.MeasureString(
                    cmnCde.getOrgPstlAddrs(cmnCde.Org_id).Trim(), font2).Height;
                offsetY = offsetY + (int)ght;
                //Contacts Nos
                nwLn = cmnCde.breakRptTxtDown(
                    cmnCde.getOrgContactNos(cmnCde.Org_id),
                    pageWidth, font2, g);
                for (int i = 0; i < nwLn.Length; i++)
                {
                    g.DrawString(nwLn[i]
                                 , font2, Brushes.Black, startX + picWdth, startY + offsetY);
                    offsetY += font2Hght;
                }
                //Email Address
                nwLn = cmnCde.breakRptTxtDown(
                    cmnCde.getOrgEmailAddrs(cmnCde.Org_id),
                    pageWidth, font2, g);
                for (int i = 0; i < nwLn.Length; i++)
                {
                    g.DrawString(nwLn[i]
                                 , font2, Brushes.Black, startX + picWdth, startY + offsetY);
                    offsetY += font2Hght;
                }
                offsetY += font2Hght;
                if (offsetY < (int)picHght)
                {
                    offsetY = font2Hght + (int)picHght;
                }
            }
            //DataSet dtst = Global.get_One_MsPyDet(long.Parse(this.msPyIDTextBox.Text));
            //Title
            for (int a = this.prntIdx; a < this.richTextBox1.Lines.GetLength(0); a++)
            {
                if (a == 0)
                {
                    nwLn = cmnCde.breakRptTxtDown(
                        this.richTextBox1.Lines[a].ToString(), pageWidth - 40, font1, g);
                    for (int i = 0; i < nwLn.Length; i++)
                    {
                        g.DrawString(nwLn[i]
                                     , font1, Brushes.Black, startX, startY + offsetY);
                        offsetY += font1Hght;
                    }
                    offsetY += font1Hght;
                }
                else
                {
                    nwLn = cmnCde.breakRptTxtDown(
                        this.richTextBox1.Lines[a].ToString(), pageWidth - 40, font3, g);
                    if (this.richTextBox1.Lines[a].ToString().Contains("==="))
                    {
                        txtwdth = g.MeasureString(
                            this.richTextBox1.Lines[a].ToString().Replace(" ", ""), font3).Width;
                    }
                    for (int i = 0; i < nwLn.Length; i++)
                    {
                        g.DrawString(nwLn[i]
                                     , font3, Brushes.Black, startX, startY + offsetY);
                        offsetY += font3Hght;
                    }
                }
                if (offsetY >= (pageHeight - 100.0F))
                {
                    e.HasMorePages = true;
                    offsetY        = 40;
                    this.pageNo++;
                    this.prntIdx = a;
                    return;
                }
            }

            //Slogan:
            offsetY += font3Hght;
            offsetY += font3Hght;
            g.DrawLine(aPen, startX, startY + offsetY, startX + txtwdth - 15,
                       startY + offsetY);
            offsetY += font3Hght;
            nwLn     = cmnCde.breakRptTxtDown(
                cmnCde.getOrgSlogan(cmnCde.Org_id),
                pageWidth - ght, font5, g);
            for (int i = 0; i < nwLn.Length; i++)
            {
                g.DrawString(nwLn[i]
                             , font5, Brushes.Black, startX, startY + offsetY);
                offsetY += font5Hght;
            }
            offsetY += font5Hght;
            nwLn     = cmnCde.breakRptTxtDown(
                "Software Developed by Rhomicom Systems Technologies Ltd.",
                pageWidth + 40, font5, g);
            for (int i = 0; i < nwLn.Length; i++)
            {
                g.DrawString(nwLn[i]
                             , font5, Brushes.Black, startX, startY + offsetY);
                offsetY += font5Hght;
            }
            nwLn = cmnCde.breakRptTxtDown(
                "Website:www.rhomicomgh.com",
                pageWidth + 40, font5, g);
            for (int i = 0; i < nwLn.Length; i++)
            {
                g.DrawString(nwLn[i]
                             , font5, Brushes.Black, startX, startY + offsetY);
                offsetY += font5Hght;
            }
        }