/// <summary> /// Ve mot duong thang tren file Pdf /// </summary> /// <param name="line"></param> /// <param name="page"></param> public static void PrintPdfLine(FosLine line, PagePdf page) { PdfContentByte cb = writer.DirectContent; cb.SaveState(); //canh chinh lai toa do cho phu hop //covan de PdfHelper.ConvertToPointPdf(line.PointStart, page); PdfHelper.ConvertToPointPdf(line.PointDest, page); cb.SetLineWidth(line.LineSize); switch (line.LineStyle) { case LineStyle.Dot: cb.SetLineDash(1f, 1f); break; case LineStyle.Nomar: cb.SetLineCap(1); break; } cb.MoveTo(line.PointStart.XPoint, line.PointStart.YPoint); cb.LineTo(line.PointDest.XPoint, line.PointDest.YPoint); cb.Stroke(); cb.RestoreState(); //sau khi ve xong phai tra lai toa do de ve lai trang khac PdfHelper.ConvertToPointPdf(line.PointStart, page); PdfHelper.ConvertToPointPdf(line.PointDest, page); }
/// <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> /// Ve mot duong thang tren PrintDocument /// </summary> /// <param name="g"></param> /// <param name="line"></param> public static void PrintLine(Graphics g, FosLine line) { Pen blackPen = new Pen(Color.Black, 1); if (line.LineStyle == LineStyle.Dot) { float[] dashValues = { 2, 2, 2, 2 }; blackPen.DashPattern = dashValues; } g.DrawLine(blackPen, line.PointStart.XPoint, line.PointStart.YPoint, line.PointDest.XPoint, line.PointDest.YPoint); }
/// <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> /// 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); } }