Ejemplo n.º 1
0
        /// <summary>
        /// Tu Label lay ra toa do de in text
        /// </summary>
        /// <param name="control"></param>
        /// <returns></returns>
        public static FosPoint CreatePointFromLabel(FPdfLabel label)
        {
            int height = label.Size.Height;
            int size   = (int)label.Font.Size;
            int xPoint = label.Location.X;
            int yPoint = 0;

            //center
            if (label.TextAlign == ContentAlignment.MiddleLeft ||
                label.TextAlign == ContentAlignment.MiddleCenter ||
                label.TextAlign == ContentAlignment.MiddleRight)
            {
                yPoint = (label.Location.Y + (label.Size.Height - size) / 2) - 1;
            }
            //top
            if (label.TextAlign == ContentAlignment.TopLeft ||
                label.TextAlign == ContentAlignment.TopCenter ||
                label.TextAlign == ContentAlignment.TopRight)
            {
                yPoint = label.Location.Y;
            }
            ////bottom
            if (label.TextAlign == ContentAlignment.BottomLeft ||
                label.TextAlign == ContentAlignment.BottomCenter ||
                label.TextAlign == ContentAlignment.BottomRight)
            {
                yPoint = label.Location.Y + (label.Size.Height - size - 2);
            }
            FosPoint point = new FosPoint(xPoint, yPoint);

            return(point);
        }
Ejemplo n.º 2
0
 public FosLine(FosPoint pointStart, FosPoint pointDest)
 {
     this.pointStart = pointStart;
     this.pointDest  = pointDest;
     this.lineSize   = 1;
     this.LineStyle  = LineStyle.Nomar;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// In border cho label
 /// </summary>
 /// <param name="tb"></param>
 /// <param name="page"></param>
 /// <param name="rootPoint"></param>
 public static void PrintBorderLabel(FPdfLabel tb, FosPoint rootPoint)
 {
     if (tb.IsShowLineTop)
     {
         FosLine lineTop = new FosLine();
         lineTop.PointStart = new FosPoint(rootPoint.XPoint + tb.Location.X, rootPoint.YPoint + tb.Location.Y);
         lineTop.PointDest  = new FosPoint(rootPoint.XPoint + tb.Location.X + tb.Width, rootPoint.YPoint + tb.Location.Y);
         if (tb.LineStyleTop == System.Drawing.Drawing2D.DashStyle.Dot)
         {
             lineTop.LineStyle = LineStyle.Dot;
         }
         if (CurPage == 1)
         {
             lsLineInpage.Add(lineTop);
         }
     }
     if (tb.IsShowLineBottom)
     {
         FosLine lineBottom = new FosLine();
         lineBottom.PointStart = new FosPoint(rootPoint.XPoint + tb.Location.X, rootPoint.YPoint + tb.Location.Y + tb.Height);
         lineBottom.PointDest  = new FosPoint(rootPoint.XPoint + tb.Location.X + tb.Width, rootPoint.YPoint + tb.Location.Y + tb.Height);
         if (tb.LineStyleBottom == System.Drawing.Drawing2D.DashStyle.Dot)
         {
             lineBottom.LineStyle = LineStyle.Dot;
         }
         if (CurPage == 1)
         {
             lsLineInpage.Add(lineBottom);
         }
     }
     if (tb.IsShowLineLeft)
     {
         FosLine lineLeft = new FosLine();
         lineLeft.PointStart = new FosPoint(rootPoint.XPoint + tb.Location.X, rootPoint.YPoint + tb.Location.Y);
         lineLeft.PointDest  = new FosPoint(rootPoint.XPoint + tb.Location.X, rootPoint.YPoint + tb.Location.Y + tb.Height);
         if (tb.LineStyleLeft == System.Drawing.Drawing2D.DashStyle.Dot)
         {
             lineLeft.LineStyle = LineStyle.Dot;
         }
         if (CurPage == 1)
         {
             lsLineInpage.Add(lineLeft);
         }
     }
     if (tb.IsShowLineRight)
     {
         FosLine lineRight = new FosLine();
         lineRight.PointStart = new FosPoint(rootPoint.XPoint + tb.Location.X + tb.Width, rootPoint.YPoint + tb.Location.Y);
         lineRight.PointDest  = new FosPoint(rootPoint.XPoint + tb.Location.X + tb.Width, rootPoint.YPoint + tb.Location.Y + tb.Height);
         if (tb.LineStyleRight == System.Drawing.Drawing2D.DashStyle.Dot)
         {
             lineRight.LineStyle = LineStyle.Dot;
         }
         if (CurPage == 1)
         {
             lsLineInpage.Add(lineRight);
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// In chu len file Pdf dua vao label
        /// </summary>
        /// <param name="FPdfText"></param>
        /// <param name="page"></param>
        /// <param name="rootPoint"></param>
        /// <param name="curPage"></param>
        public static void PrintPdfString(FPdfLabel FPdfLabel, PagePdf page, FosPoint rootPoint, int curPage)
        {
            //Inborder
            PrintBorderLabel(FPdfLabel, page, rootPoint);
            //InBackColor
            PrintBackColor(FPdfLabel, page, rootPoint);

            //khoi tao bien de in text
            PdfContentByte cb = writer.DirectContent;

            cb.SaveState();
            BaseFont bf;

            if (FPdfLabel.Font.Italic)
            {
                bf = BaseFont.CreateFont(@"C:\WINDOWS\Fonts\ariali.TTF", BaseFont.IDENTITY_H, true);
            }
            else
            {
                bf = BaseFont.CreateFont(@"C:\WINDOWS\Fonts\Arial.TTF", BaseFont.IDENTITY_H, true);
            }
            //set Font
            float size = (float)FPdfLabel.Font.Size + (float)FPdfLabel.Font.Size / 3;

            cb.SetFontAndSize(bf, size);
            if (FPdfLabel.Font.Bold)
            {
                cb.SetLineWidth(0.5);
                cb.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);
            }
            else
            {
                cb.SetLineWidth(0);
                cb.SetTextRenderingMode(PdfContentByte.ALIGN_LEFT);
            }

            // tao bien tao do
            FosPoint point = CreatePointFromLabel(FPdfLabel);

            // Tuy vao control cha la gi ma chinh lai toa do
            point.XPoint += rootPoint.XPoint;
            point.YPoint += rootPoint.YPoint;
            //canh chinh lai toa do cho phu hop
            PdfHelper.ConvertToPointPdf(point, page);
            //Lay du lieu cua dataSource bo vao text
            GetDataFPdfLabel(FPdfLabel, curPage);
            string text = FPdfLabel.Text;

            //if (text.Trim() == "")
            //    return;
            //canh lai center hoac right
            point.XPoint += AlignforFPdfLabel(FPdfLabel as FPdfLabel);
            cb.BeginText();
            cb.ShowTextAligned(0, text, point.XPoint, point.YPoint, FPdfLabel.FPdfProperties.Rotation);
            cb.EndText();
            cb.RestoreState();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Tu textbox lay ra toa do de in text
        /// </summary>
        /// <param name="control"></param>
        /// <returns></returns>
        public static FosPoint CreatePointFromControl(FPdfText textbox)
        {
            int      height = textbox.Size.Height;
            int      size   = (int)textbox.Font.Size;
            int      xPoint = textbox.Location.X + 4;
            int      yPoint = textbox.Location.Y + size + (textbox.Size.Height - size) / 2;
            FosPoint point  = new FosPoint(xPoint, yPoint);

            return(point);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// In Hinh anh len PrintDocument
 /// </summary>
 /// <param name="g"></param>
 /// <param name="pB"></param>
 /// <param name="rootPoint"></param>
 public static void PrintImage(Graphics g, PictureBox pB, FosPoint rootPoint)
 {
     try
     {
         Image img = pB.Image;
         g.DrawImage(img, pB.Location.X + rootPoint.XPoint, pB.Location.Y + rootPoint.YPoint, pB.Width, pB.Height);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// In Backcolor cho Label
        /// </summary>
        /// <param name="g"></param>
        /// <param name="FPdfLabel"></param>
        /// <param name="rootPoint"></param>
        public static void PrintBackColor(Graphics g, FPdfLabel FPdfLabel, FosPoint rootPoint)
        {
            if (FPdfLabel.BackColor == Color.White || FPdfLabel.BackColor == Color.Transparent)
            {
                return;
            }
            // Create solid brush.
            SolidBrush blueBrush = new SolidBrush(FPdfLabel.BackColor);

            // Create rectangle.
            Rectangle rect = new Rectangle((int)rootPoint.XPoint + FPdfLabel.Location.X, (int)rootPoint.YPoint + FPdfLabel.Location.Y, FPdfLabel.Size.Width, FPdfLabel.Size.Height);

            // Fill rectangle to screen.
            g.FillRectangle(blueBrush, rect);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Dua vao Label Viet chu len PrintDocument
        /// </summary>
        /// <param name="g"></param>
        /// <param name="FPdfLabel"></param>
        /// <param name="rootPoint"></param>
        /// <param name="curPage"></param>
        private static void PrintString(Graphics g, FPdfLabel FPdfLabel, FosPoint rootPoint, int curPage)
        {
            //In Backcolor
            PrintBackColor(g, FPdfLabel, rootPoint);
            //Inborder
            PrintBorderLabel(FPdfLabel, rootPoint);
            // tao bien tao do
            FosPoint point = CreatePointFromLabel(FPdfLabel);

            // Tuy vao control cha la gi ma chinh lai toa do
            point.XPoint += rootPoint.XPoint;
            point.YPoint += rootPoint.YPoint;
            //Lay du lieu cua dataSource bo vao text
            GetDataFPdfLabel(FPdfLabel, curPage);
            string text = FPdfLabel.Text;

            point.XPoint += AlignforFPdfLabel(FPdfLabel as FPdfLabel);
            g.DrawString(text, FPdfLabel.Font, new SolidBrush(FPdfLabel.ForeColor), point.XPoint, point.YPoint);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// In BackColor cho control
        /// </summary>
        /// <param name="ct"></param>
        /// <param name="page"></param>
        /// <param name="rootPoint"></param>
        public static void PrintBackColor(Control ct, PagePdf page, FosPoint rootPoint)
        {
            if (ct.BackColor == Color.White || ct.BackColor == Color.Transparent)
            {
                return;
            }
            PdfContentByte over = writer.DirectContent;
            BaseColor      bc   = new BaseColor(ct.BackColor);

            over.SaveState();
            FosPoint point = new FosPoint(ct.Location.X, ct.Location.Y + ct.Height);

            point.XPoint += rootPoint.XPoint;
            point.YPoint += rootPoint.YPoint;
            PdfHelper.ConvertToPointPdf(point, page);
            over.Rectangle(point.XPoint, point.YPoint, ct.Width, ct.Height);
            over.SetColorFill(bc);
            over.Fill();
            over.RestoreState();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// In mot picturebox tren form ra mot hinh anh tren file Pdf
        /// </summary>
        /// <param name="pB"></param>
        /// <param name="page"></param>
        /// <param name="rootPoint"></param>
        public static void PrinPdfImage(PictureBox pB, PagePdf page, FosPoint rootPoint)
        {
            BaseColor bc = new BaseColor(255, 255, 255);

            try
            {
                var logo = iTextSharp.text.Image.GetInstance(pB.Image, bc);
                //xet toa do, goc toa do la goc phan |_
                FosPoint point = new FosPoint(pB.Location.X + rootPoint.XPoint, pB.Location.Y + pB.Size.Height + rootPoint.YPoint);
                PdfHelper.ConvertToPointPdf(point, page);
                logo.SetAbsolutePosition(point.XPoint, point.YPoint);
                //xet kich thuoc
                logo.ScaleAbsoluteHeight(pB.Size.Height);
                logo.ScaleAbsoluteWidth(pB.Size.Width);
                doc.Add(logo);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// tao border cho cac control
        /// </summary>
        /// <param name="ct"></param>
        /// <param name="page"></param>
        /// <param name="rootPoint"></param>
        public static void PrintBorderForControl(Control ct, FosPoint rootPoint)
        {
            FosLine line1 = new FosLine();

            line1.PointStart = new FosPoint(rootPoint.XPoint + ct.Location.X, rootPoint.YPoint + ct.Location.Y);
            line1.PointDest  = new FosPoint(rootPoint.XPoint + ct.Location.X + ct.Width, rootPoint.YPoint + ct.Location.Y);
            if (CurPage == 1)
            {
                lsLineInpage.Add(line1);
            }

            FosLine line2 = new FosLine();

            line2.PointStart = new FosPoint(rootPoint.XPoint + ct.Location.X, rootPoint.YPoint + ct.Location.Y + ct.Height);
            line2.PointDest  = new FosPoint(rootPoint.XPoint + ct.Location.X + ct.Width, rootPoint.YPoint + ct.Location.Y + ct.Height);
            if (CurPage == 1)
            {
                lsLineInpage.Add(line2);
            }

            FosLine line3 = new FosLine();

            line3.PointStart = new FosPoint(rootPoint.XPoint + ct.Location.X, rootPoint.YPoint + ct.Location.Y);
            line3.PointDest  = new FosPoint(rootPoint.XPoint + ct.Location.X, rootPoint.YPoint + ct.Location.Y + ct.Height);
            if (CurPage == 1)
            {
                lsLineInpage.Add(line3);
            }

            FosLine line4 = new FosLine();

            line4.PointStart = new FosPoint(rootPoint.XPoint + ct.Location.X + ct.Width, rootPoint.YPoint + ct.Location.Y);
            line4.PointDest  = new FosPoint(rootPoint.XPoint + ct.Location.X + ct.Width, rootPoint.YPoint + ct.Location.Y + ct.Height);
            if (CurPage == 1)
            {
                lsLineInpage.Add(line4);
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// In tat ca cac control co trong Panel
 /// </summary>
 /// <param name="panel"></param>
 /// <param name="page"></param>
 /// <param name="curPage"></param>
 /// <param name="rootPoint"></param>
 public static void PrintAllControlInPanel(Graphics g, FPdfPanel panel, int curPage, FosPoint rootPoint)
 {
     //Add line
     if (panel.lsPdfLine.Count > 0)
     {
         foreach (FosLine line in panel.lsPdfLine)
         {
             if (curPage == 1)
             {
                 FosLine lineNew = new FosLine(new FosPoint(), new FosPoint());
                 lineNew.PointStart.XPoint = rootPoint.XPoint + line.PointStart.XPoint;
                 lineNew.PointStart.YPoint = rootPoint.YPoint + line.PointStart.YPoint;
                 lineNew.PointDest.XPoint  = rootPoint.XPoint + line.PointDest.XPoint;
                 lineNew.PointDest.YPoint  = rootPoint.YPoint + line.PointDest.YPoint;
                 lsLineInpage.Add(lineNew);
             }
         }
     }
     // In hinh dau tien
     foreach (Control c in panel.Controls)
     {
         if (c is PictureBox)
         {
             PictureBox pB = c as PictureBox;
             PrintImage(g, pB, rootPoint);
         }
     }
     //Sau do in chu
     foreach (Control c in panel.Controls)
     {
         //if (c is FPdfText)
         //{
         //    FPdfText FPdfText = c as FPdfText;
         //    PrinString(FPdfText, page, rootPoint, curPage);
         //}
         if (c is FPdfLabel)
         {
             FPdfLabel FPdfLabel = c as FPdfLabel;
             PrintString(g, FPdfLabel, rootPoint, curPage);
         }
         //in Panel con
         if (c is FPdfPanel)
         {
             FPdfPanel FPdfPanelChirld = c as FPdfPanel;
             //inborder
             if (FPdfPanelChirld.BorderStyle == BorderStyle.FixedSingle)
             {
                 PrintBorderForControl(FPdfPanelChirld, rootPoint);
             }
             PrintAllControlInPanel(g, FPdfPanelChirld, curPage, new FosPoint(rootPoint.XPoint + FPdfPanelChirld.Location.X, rootPoint.YPoint + FPdfPanelChirld.Location.Y));
         }
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Chuyen doi toa đo giua Form va file Pdf
 /// </summary>
 /// <param name="point"></param>
 /// <param name="page"></param>
 public static void ConvertToPointPdf(FosPoint point, PagePdf page)
 {
     point.YPoint = page.Height - point.YPoint;
 }