/// <summary>
 /// Печатает шапку, которая одинакова на каждой странице
 /// </summary>
 /// <param name="doc">Документ </param>
 /// <param name="cb">PdfContentByte</param>
 /// <param name="basefont">Шрифт</param>
 /// <param name="ttf">Путь до базового шрифта</param>
 private void HatsPrint(Document doc, PdfContentByte cb, BaseFont basefont, string ttf)
 {
     Hat.IMGPrint(doc);
     Hat.DetailsPrint(cb, basefont);
     // Hat.LinePrint(doc, 1.5f, 100.0f, BaseColor.BLACK, 0, 1);
 }
 /// <summary>
 /// Печатает нижнюю полосу которая одинакова на всех страницах КРОМЕ номера страницы
 /// </summary>
 /// <param name="cb"></param>
 /// <param name="basefont"></param>
 /// <param name="number"></param>
 private void LowHatPrint(PdfContentByte cb, BaseFont basefont, int number)
 {
     Hat.LinePrint(cb, 20, 20, 575, 20, 0, 0, 0);
     Hat.DetailsPrint(cb, basefont, BigTextData.Markets, 90, 25, 6);
     Hat.DetailsPrint(cb, basefont, "Page : " + number.ToString(), 297, 34, 6);
 }
        private void ReportAsync()
        {
            CloseReport();
            Document doc = new Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);

            using (var writer = PdfWriter.GetInstance(doc, new FileStream(path + DpfName, FileMode.Create, FileAccess.ReadWrite)))
            {
                int                  page     = 1;
                BaseFont             baseFont = BaseFont.CreateFont(ttf, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                iTextSharp.text.Font font     = new iTextSharp.text.Font(baseFont, iTextSharp.text.Font.DEFAULTSIZE, iTextSharp.text.Font.NORMAL);
                iTextSharp.text.Font fontbold = new iTextSharp.text.Font(baseFont, iTextSharp.text.Font.DEFAULTSIZE, iTextSharp.text.Font.BOLD);

                doc.Open();
                PdfContentByte cb = writer.DirectContent;

                #region 1 page
                doc.NewPage();
                doc.Add(new Paragraph("", font));
                HatsPrint(doc, cb, baseFont, ttf);

                cb.BeginText();
                cb.ShowTextAligned(0, "Chart", 300, 680, 0);
                cb.EndText();
                iTextSharp.text.Image HistoryChartIMG = Pcp.ImgScreenSchots(Dynamic, 0, 0);
                HistoryChartIMG.SetAbsolutePosition(25, 560);
                HistoryChartIMG.ScaleAbsolute(560, 95);
                cb.AddImage(HistoryChartIMG);

                Hat.DetailsPrint(cb, baseFont, "Return", 25, 545, 10);

                PDFTablesCreate tablecreator = new PDFTablesCreate(ActivesClasses, Convert.ToDecimal(Totalport));

                PdfPTable table = new PdfPTable(3);
                table = Pcp.TablePrint(null, font, tablecreator.ReturnT, 90, 45, 95);
                table.WriteSelectedRows(0, -1, 25, 530, cb);


                Hat.DetailsPrint(cb, baseFont, "Allocation", 325, 545, 10);
                table = new PdfPTable(3);
                table = Pcp.TablePrint(null, font, tablecreator.AllocationT, 90, 50, 100);
                table.WriteSelectedRows(0, -1, 325, 530, cb);
                LowHatPrint(cb, baseFont, page);
                page++;

                #endregion
                #region 2 page - 3diagramm
                doc.NewPage();
                HatsPrint(doc, cb, baseFont, ttf);

                Hat.DetailsPrint(cb, baseFont, "Current Portfel Chart", Convert.ToInt32(doc.PageSize.Width / 2 - 60), 680, 10);
                iTextSharp.text.Image CurrentPotrIMG = Pcp.ImgScreenSchots(CurrentP, 21, 21);
                CurrentPotrIMG.SetAbsolutePosition(0, 300);                //1 картинка
                                                                           //CurrentPotrIMG.ScaleAbsolute(440, 190);
                                                                           //CurrentPotrIMG.ScaleAbsolute(200,200);
                cb.AddImage(CurrentPotrIMG);
                Hat.LinePrint(cb, 20, 523, 550, 523, 255, 255, 255, 26);   // закрасить сверху
                Hat.LinePrint(cb, 20, 555, -120, 255, 255, 255, 255, 219); //закрасить слева


                //Легенда
                var      colorsPortfels = Ext.CurPortBrush;
                int      X = 465; int Y = 670;
                object   KeyDiagramm = null;
                Diagramm dd          = null;
                string   isin        = null;

                for (int i = 0; i < colorsPortfels.Count; i++)
                {
                    System.Windows.Media.Brush diagrammitem = colorsPortfels.Values.ElementAt(i);
                    KeyDiagramm = colorsPortfels.Keys.ElementAt(i);
                    dd          = (Diagramm)KeyDiagramm;
                    isin        = dd.Name;
                    Pcp.RectangleTextPrint(cb, baseFont, isin, diagrammitem, X, Y);
                    Y = Y - 15;
                }
                //
                LowHatPrint(cb, baseFont, page);
                page++;
                #endregion

                #region 3p Transactions
                doc.NewPage();
                HatsPrint(doc, cb, baseFont, ttf);
                string date = DateTime.Now.ToString().Remove(11);

                Hat.DetailsPrint(cb, baseFont, "Cell Results  * " + date, Convert.ToInt32(doc.PageSize.Width / 2 - 60),
                                 Convert.ToInt32(doc.PageSize.Height - 150), 10);
                table = Pcp.TablePrint(null, font, tablecreator.CellPolicy, 100, 100, 100, 130);
                table.WriteSelectedRows(0, -1, 100, 680, cb);

                Hat.DetailsPrint(cb, baseFont, "Holdings * " + date, Convert.ToInt32(doc.PageSize.Width / 2 - 60), Convert.ToInt32(doc.PageSize.Height - 270), 10);
                font.Size = 8;
                table     = Pcp.TablePrint(new byte[] { 255, 255, 255 }, font, tablecreator.Holdings, 53, 35, 50, 55, 50, 70, 65, 70, 60, 50);
                table.WriteSelectedRows(0, -1, 25, 560, cb);
                LowHatPrint(cb, baseFont, page);



                table = new PdfPTable(5);
                var TBL   = tablecreator.Transactions;
                var Count = Math.Abs(TBL.Rows.Count / 50) + 1;
                for (int i = 0; i < Count; i++)
                {
                    doc.NewPage();
                    HatsPrint(doc, cb, baseFont, ttf);
                    Hat.DetailsPrint(cb, baseFont, "Transactions * " + date, Convert.ToInt32(doc.PageSize.Width / 2 - 60),
                                     Convert.ToInt32(doc.PageSize.Height - 150), 10);
                    table = Pcp.TablePrint(null, font, TBL, 103, 103, 103, 103, 103, 0, 0, 0, 0, 0, i, 50, Count - 1);
                    table.WriteSelectedRows(0, -1, 25, 680, cb);
                    page++;
                    LowHatPrint(cb, baseFont, page);
                }
                page++;

                #endregion

                #region N page - end
                doc.NewPage();


                HatsPrint(doc, cb, baseFont, ttf);



                cb.BeginText();
                cb.ShowTextAligned(0, "Important Remarks : ", 30, 680, 0);

                ColumnText ct     = new ColumnText(cb);
                Phrase     myText = new Phrase(BigTextData.Remarks, font);
                ct.SetSimpleColumn(myText, 30, 665, 580, 317, 15, Element.ALIGN_LEFT);
                ct.Go();



                cb.EndText();
                LowHatPrint(cb, baseFont, page);
                #endregion
                doc.Close();
            }
            if (open == true)
            {
                OpenReport();
            }
        }