/// <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); }
/// <summary> /// Canh trai, phai, giua cho label /// </summary> /// <param name="lb"></param> /// <returns></returns> public static int AlignforFPdfLabel(FPdfLabel lb) { double align; double width = lb.Size.Width; using (Bitmap tempImage = new Bitmap(lb.Size.Width, lb.Size.Height)) { SizeF stringSize = Graphics.FromImage(tempImage).MeasureString(lb.Text, lb.Font); align = width - stringSize.Width; } if (lb.TextAlign == ContentAlignment.TopCenter || lb.TextAlign == ContentAlignment.MiddleCenter || lb.TextAlign == ContentAlignment.BottomCenter) { align = align / 2; } if (lb.TextAlign == ContentAlignment.TopLeft || lb.TextAlign == ContentAlignment.MiddleLeft || lb.TextAlign == ContentAlignment.BottomLeft) { align = 0; } if (lb.TextAlign == ContentAlignment.TopRight || lb.TextAlign == ContentAlignment.MiddleRight || lb.TextAlign == ContentAlignment.BottomRight) { align = align - 4; } return((int)Math.Round(align, MidpointRounding.AwayFromZero)); }
public static void CoppyFPFPanelDetail(FPdfPanel panelSource, FPdfPanel panelDest, int row) { panelDest.Size = panelSource.Size; panelDest.DataSource = panelSource.DataSource; panelDest.lsPdfLine = panelSource.lsPdfLine; panelDest.BorderStyle = panelSource.BorderStyle; //panelDest.AddControlEx += new AddControl( panelSource.AddControlEx); panelSource.CoppyAddEvent(panelDest); foreach (Control ct in panelSource.Controls) { if (ct is FPdfText) { FPdfText tb = new FPdfText(); CopyFPdfText(ct as FPdfText, tb, row); panelDest.Controls.Add(tb); panelDest.RaiseAddControlEvent(tb); } else if (ct is FPdfLabel) { FPdfLabel lb = new FPdfLabel(); CopyFPdfLabel(ct as FPdfLabel, lb, row); panelDest.Controls.Add(lb); panelDest.RaiseAddControlEvent(lb); } } }
/// <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); } } }
/// <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(); }
/// <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)); } } }
/// <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); }
/// <summary> /// Lay du lieu cho Label dua vao DataSource cua Detail /// </summary> /// <param name="FPdfText"></param> /// <param name="curPage"></param> public static void GetDataFPdfLabel(FPdfLabel FPdfLabel, int curPage) { if (FPdfLabel.Parent is FPdfPanel && (FPdfLabel.Parent as FPdfPanel).DataSource != null && (FPdfLabel.Parent as FPdfPanel).DataSource.Rows.Count != 0 && (FPdfLabel.Parent as FPdfPanel).DataSource.Columns.Contains(FPdfLabel.FPdfProperties.TableColumn)) { DataTable dt = (FPdfLabel.Parent as FPdfPanel).DataSource; int row = ((curPage - 1) * MaxRow + FPdfLabel.FPdfProperties.TableRow); if (row >= dt.Rows.Count) { FPdfLabel.Text = ""; return; } FPdfLabel.Text = dt.Rows[row][FPdfLabel.FPdfProperties.TableColumn] + ""; } }
/// <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); }
public static void CopyFPdfLabel(FPdfLabel lbSource, FPdfLabel lbDest, int row) { lbDest.Size = lbSource.Size; lbDest.Font = lbSource.Font; lbDest.Location = lbSource.Location; lbDest.TextAlign = lbSource.TextAlign; //lbDest.Text = lbSource.Text; lbDest.BorderStyle = lbSource.BorderStyle; lbDest.BackColor = lbSource.BackColor; lbDest.FPdfProperties.TableRow = row; lbDest.FPdfProperties.TableColumn = lbSource.FPdfProperties.TableColumn; lbDest.IsShowLineTop = lbSource.IsShowLineTop; lbDest.LineStyleTop = lbSource.LineStyleTop; lbDest.IsShowLineBottom = lbSource.IsShowLineBottom; lbDest.LineStyleBottom = lbSource.LineStyleBottom; lbDest.IsShowLineRight = lbSource.IsShowLineRight; lbDest.LineStyleRight = lbSource.LineStyleRight; lbDest.IsShowLineLeft = lbSource.IsShowLineLeft; lbDest.LineStyleLeft = lbSource.LineStyleLeft; }