コード例 #1
0
        private void AddTablaPrincipal(PdfPage page)
        {
            var dataTable = new DataTable();

            dataTable.Columns.Add(PDF_Resources.Header_Parametro);
            dataTable.Columns.Add(PDF_Resources.Header_Puntaje);
            dataTable.Columns.Add(PDF_Resources.Header_Percentil);
            dataTable.Columns.Add(PDF_Resources.Header_Orientacion);

            int rows    = datos.TNotaciones.Parametros.Length;
            int columns = dataTable.Columns.Count;

            PdfTable myPdfTable = pdfDocument.NewTable(Function_Library.FontTexto11, rows, columns, 3);

            var str_orientacion = new[]
            {
                datos.Orientaciones.O_indice_atencion_total,
                //datos.O_Error_estandar_IA,
                datos.Orientaciones.O_Aciertos,
                datos.Orientaciones.O_Omision,
                datos.Orientaciones.O_Comision,
                datos.Orientaciones.O_TR,
                datos.Orientaciones.O_ErrorTR,
                datos.Orientaciones.O_d,
                datos.Orientaciones.O_C
            };

            for (int i = 0; i < datos.TNotaciones.Parametros.Length; i++)
            {
                DataRow row = dataTable.NewRow();
                row[PDF_Resources.Header_Parametro]   = datos.TNotaciones.Parametros[i];
                row[PDF_Resources.Header_Puntaje]     = FunctionLibrary.ShowDouble(datos.Puntuaciones[i]);
                row[PDF_Resources.Header_Percentil]   = (i >= 6 && i <= 7) ? string.Empty : FunctionLibrary.ShowDouble(datos.TNotaciones[i]);
                row[PDF_Resources.Header_Orientacion] = str_orientacion[i];
                dataTable.Rows.Add(row);
            }

            myPdfTable.ImportDataTable(dataTable);
            myPdfTable.HeadersRow.SetColors(Color.Black, Color.FromArgb(229, 229, 229));
            myPdfTable.SetColors(Color.Black, Color.White);
            myPdfTable.SetBorders(Color.Black, 1, BorderType.CompleteGrid);
            myPdfTable.SetColumnsWidth(new[] { 35, 12, 12, 41 });
            myPdfTable.SetContentAlignment(ContentAlignment.TopLeft);
            myPdfTable.HeadersRow[0].SetContent(string.Empty);
            myPdfTable.Columns[0].SetBackgroundColor(Color.FromArgb(242, 242, 242));
            PdfTablePage newPdfTablePage = myPdfTable.CreateTablePage(new PdfArea(pdfDocument, 80, 480, 450, 420));

            page.Add(newPdfTablePage);
        }
コード例 #2
0
        public Stream SaveAsStream()
        {
            table.EndLoadData();
            table.AcceptChanges();

            var removes = new List <string>();

            foreach (DataColumn dc in table.Columns)
            {
                if (title.IndexOf(dc.ColumnName) == -1)
                {
                    removes.Add(dc.ColumnName);
                }
            }

            foreach (var name in removes)
            {
                table.Columns.Remove(name);
            }

            var pdfTitle = table.TableName;

            // Starting instantiate the document.
            // Remember to set the Docuement Format. In this case, we specify width and height.
            PdfDocument myPdfDocument = new PdfDocument(PdfDocumentFormat.InCentimeters(21, 29.7));

            // Now we create a Table of 100 lines, 6 columns and 4 points of Padding.
            PdfTable myPdfTable = myPdfDocument.NewTable(new Font("Arial", 12), table.Rows.Count, table.Columns.Count, 4);

            // Importing datas from the datatables... (also column names for the headers!)
            //myPdfTable.ImportDataTable(Table);
            myPdfTable.ImportDataTable(table);

            // Sets the format for correct date-time representation
            //myPdfTable.Columns[2].SetContentFormat("{0:dd/MM/yyyy}");

            // Now we set our Graphic Design: Colors and Borders...
            myPdfTable.HeadersRow.SetColors(Color.White, Color.Navy);
            myPdfTable.SetColors(Color.Black, Color.White, Color.Gainsboro);
            myPdfTable.SetBorders(Color.Black, 1, BorderType.CompleteGrid);

            //// With just one method we can set the proportional width of the columns.
            //// It's a "percentage like" assignment, but the sum can be different from 100.
            //myPdfTable.SetColumnsWidth(new int[] { 5, 25, 16, 20, 20, 15 });

            //// You can also set colors for a range of cells, in this case, a row:
            //myPdfTable.Rows[7].SetColors(Color.Black, Color.LightGreen);

            // Now we set some alignment... for the whole table and then, for a column.
            myPdfTable.SetContentAlignment(ContentAlignment.MiddleCenter);
            myPdfTable.Columns[1].SetContentAlignment(ContentAlignment.MiddleLeft);

            // Here we start the loop to generate the table...
            while (!myPdfTable.AllTablePagesCreated)
            {
                // we create a new page to put the generation of the new TablePage:
                PdfPage      newPdfPage      = myPdfDocument.NewPage();
                PdfTablePage newPdfTablePage = myPdfTable.CreateTablePage(new PdfArea(myPdfDocument, 48, 120, 500, 670));

                // we also put a Label
                PdfTextArea pta = new PdfTextArea(new Font("Arial", 26, FontStyle.Bold), Color.Red
                                                  , new PdfArea(myPdfDocument, 0, 20, 595, 120), ContentAlignment.MiddleCenter, pdfTitle);

                // nice thing: we can put all the objects in the following lines, so we can have
                // a great control of layer sequence...
                newPdfPage.Add(newPdfTablePage);
                newPdfPage.Add(pta);

                // we save each generated page before start rendering the next.
                newPdfPage.SaveToDocument();
            }


            //myPdfDocument.SaveToFile("Example1.pdf");
            var stream = new MemoryStream();

            myPdfDocument.SaveToStream(stream);
            return(stream);
        }
コード例 #3
0
        public System.IO.FileStream GeneraBustaPdf(DataTable dtProfile, string userId)
        {
            System.IO.FileStream fsout = null;
            try
            {
                PdfDocument myPdfDocument = new PdfDocument(PdfDocumentFormat.InCentimeters(22.9, 16.2));

                foreach (DataRow row in dtProfile.Rows)
                {
                    //Creo la una tabella di 3 righe, 1 colonnA e 5 ppunti di Padding.
                    PdfTable myPdfTable = myPdfDocument.NewTable(new Font("Times New Roman", 10), 3, 1, 5);

                    myPdfTable.ImportDataTable(Table(row));

                    myPdfTable.SetColors(Color.Black, Color.White);
                    myPdfTable.SetBorders(Color.Black, 1, BorderType.None);
                    myPdfTable.SetColumnsWidth(new int[] { 100 });

                    myPdfTable.VisibleHeaders = false;
                    myPdfTable.SetContentAlignment(ContentAlignment.MiddleRight);

                    while (!myPdfTable.AllTablePagesCreated)
                    {
                        PdfPage      newPdfPage      = myPdfDocument.NewPage();
                        PdfArea      newPdfArea      = new  PdfArea(myPdfDocument, 240.0, 230.0, 350.0, 200.0);
                        PdfTablePage newPdfTablePage = myPdfTable.CreateTablePage(newPdfArea);

                        PdfTextArea pta = new PdfTextArea(new Font("Times New Roman", 10, FontStyle.Regular), Color.Black, new PdfArea(myPdfDocument, 55, 145, 250, 80), ContentAlignment.TopCenter, row["VAR_DESC_REGISTRO"].ToString().Trim());
//						PdfTextArea pta=new PdfTextArea(new Font("Times New Roman",10,FontStyle.Regular),Color.Black,new PdfArea(myPdfDocument,55,145,250,80),ContentAlignment.TopCenter,"dasd sd asf af fdf f sadf asd fas fds fas dfsad fdsa fads fds f dsf dsaf dsa fsad fsa f sadf sad fsda fd fdsa fewsafrew fre gfre gf re erw gewr er rebre br be beb reb ber be b erb re bre ber be rb erbv vf ff f ff f ff fffvgvg");
                        newPdfPage.Add(newPdfTablePage);
                        newPdfPage.Add(pta);

                        newPdfPage.SaveToDocument();
                    }
                }


                string path = System.Configuration.ConfigurationManager.AppSettings["REPORTS_PATH"];
                //path = path.Replace("%DATA", "StampaB_" + userId + DateTime.Now.ToString("yyyyMMdd"));
                path = path.Replace("%DATA", "StampaBuste");
                try
                {
                    if (!System.IO.Directory.Exists(path))
                    {
                        System.IO.Directory.CreateDirectory(path);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                string nomeFile = userId + DateTime.Now.ToString("yyyyMMdd") + ".pdf";
                path = path + @"\" + nomeFile;
                System.IO.FileInfo nfile = new FileInfo(path);
                try
                {
                    if (nfile.Exists)
                    {
                        nfile.Delete();
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                myPdfDocument.SaveToFileStream(path);

                fsout = new FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            }
            catch (Exception ex)
            {
                if (fsout != null)
                {
                    fsout.Close();
                }
                throw ex;
            }

            return(fsout);
        }
コード例 #4
0
        private void ProcessStyledTable(PdfPage page, Com.Delta.Print.Engine.StyledTable table)
        {
            try
            {
                DataTable data = table.DataSource == null ? table.DisplayData : table.Data;

                int visibleColumnCount = table.GetVisibleColumnsCount();

                if (data == null)
                {
                    data = new DataTable();
                    for (int i = 0; i < visibleColumnCount; i++)
                    {
                        data.Columns.Add();
                    }
                }


                if (data.Rows.Count == 0)
                {
                    if (table.DrawEmptyRows)
                    {
                        int      maxRows  = table.Bounds.Height / table.CellHeight;
                        PdfTable pdfTable = pdfDocument.NewTable(table.DataFont, maxRows, visibleColumnCount, 2);

                        System.Data.DataTable dt = new System.Data.DataTable();
                        for (int i = 0; i < visibleColumnCount; i++)
                        {
                            dt.Columns.Add("");
                        }

                        for (int i = 0; i < table.Height / table.CellHeight; i++)
                        {
                            dt.Rows.Add(dt.NewRow());
                            if (dt.Columns.Count > 0)
                            {
                                dt.Rows[i][0] = " ";
                            }
                        }

                        pdfTable.ImportDataTable(dt);

                        pdfTable.SetRowHeight(Convert(table.CellHeight));

                        pdfTable.HeadersRow.SetRowHeight(Convert(table.CellHeight));
                        pdfTable.HeadersRow.SetColors(table.HeaderFontColor, table.HeaderBackgroundColor);
                        pdfTable.HeadersRow.SetFont(table.HeaderFont);

                        int count = 0;
                        for (int i = 0; i < table.Columns.Length; i++)
                        {
                            if (table.Columns[i].Width > 0)
                            {
                                string columnName = table.Columns[i].Label == String.Empty || table.Columns[i].Label == "" ? " " : table.Columns[i].Label;
                                pdfTable.HeadersRow[count].SetContent(columnName);
                                count++;
                            }
                        }

                        pdfTable.SetColors(table.DataFontColor, table.BackgroundColor);
                        pdfTable.SetBorders(table.BorderColor, 1, BorderType.CompleteGrid);

                        if (table.AlternateBackColor)
                        {
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                if (i % 2 == 1)
                                {
                                    pdfTable.Rows[i].SetBackgroundColor(table.AlternatingBackColor);
                                }
                            }
                        }


                        int[] columnWidths = new int[visibleColumnCount];
                        int   tableWidth   = 0;
                        count = 0;
                        for (int i = 0; i < table.Columns.Length; i++)
                        {
                            if (table.Columns[i].Width > 0)
                            {
                                columnWidths[count] = (int)Convert(table.Columns[i].Width);
                                tableWidth         += columnWidths[count];
                                count++;
                            }
                        }
                        pdfTable.SetColumnsWidth(columnWidths);

                        count = 0;
                        for (int i = 0; i < table.Columns.Length; i++)
                        {
                            if (table.Columns[i].Width > 0)
                            {
                                Com.Delta.Print.Engine.Pdf.HorizontalAlignment columnAlignment = GetColumnContentAlignment(table.Columns[i].Alignment);
                                pdfTable.HeadersRow[count].SetContentAlignment(columnAlignment, VerticalAlignment.Middle);
                                pdfTable.Columns[count].SetContentAlignment(columnAlignment, VerticalAlignment.Middle);

                                count++;
                            }
                        }

                        pdfTable.VisibleHeaders = table.DrawHeader;
                        PdfTablePage tablePage = pdfTable.CreateTablePage(new PdfArea(pdfDocument, Convert(table.Bounds.X), Convert(table.Bounds.Y), tableWidth, Convert(table.Bounds.Height)));
                        page.Add(tablePage);
                    }
                    else if (table.DrawHeader && !table.DrawEmptyRows)
                    {
                        int position = table.Bounds.X;

                        int headerRelativeHeight = 1;
                        for (int i = 0; i < table.Columns.Length; i++)
                        {
                            if (table.Columns[i].Width > 0)
                            {
                                PdfArea area = new PdfArea(pdfDocument, Convert(position + 2), Convert(table.Bounds.Y + 2), Convert(table.Columns[i].Width - 4), Convert(table.CellHeight - 4));

                                PdfTextArea pdfTextArea  = new PdfTextArea(table.HeaderFont, table.HeaderFontColor, area, GetColumnContentAlignment(table.Columns[i].Alignment), VerticalAlignment.Middle, table.Columns[i].Label, false);
                                int         minimumLines = pdfTextArea.RenderLines().Count;
                                headerRelativeHeight = Math.Max(headerRelativeHeight, minimumLines);
                            }
                        }

                        int headerHeight = table.CellHeight * headerRelativeHeight;

                        for (int i = 0; i < table.Columns.Length; i++)
                        {
                            if (table.Columns[i].Width > 0)
                            {
                                PdfArea area       = new PdfArea(pdfDocument, Convert(position + 2), Convert(table.Bounds.Y + 2), Convert(table.Columns[i].Width - 4), Convert(headerHeight - 4));
                                PdfArea borderArea = new PdfArea(pdfDocument, Convert(position), Convert(table.Bounds.Y), Convert(table.Columns[i].Width), Convert(headerHeight));

                                PdfRectangle border = new PdfRectangle(pdfDocument, borderArea, table.BorderColor, 1, table.HeaderBackgroundColor);
                                page.Add(border);

                                PdfTextArea pdfTextArea = new PdfTextArea(table.HeaderFont, table.HeaderFontColor, area, GetColumnContentAlignment(table.Columns[i].Alignment), VerticalAlignment.Middle, table.Columns[i].Label, false);

                                // arbitrary line spacing
                                pdfTextArea.SetLineSpacing(Convert(table.CellHeight / 8));
                                page.Add(pdfTextArea);

                                position += table.Columns[i].Width;
                            }
                        }
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    int maxRows  = table.Height / table.CellHeight;
                    int rowCount = data.Rows.Count;

                    PdfTable pdfTable;

                    double cellPadding = Math.Max(0, Math.Min(2, Math.Floor(0.5 * (table.CellHeight - table.DataFont.GetHeight()))));

                    if (table.DrawEmptyRows)
                    {
                        pdfTable = pdfDocument.NewTable(table.DataFont, rowCount + maxRows, visibleColumnCount, cellPadding);
                    }
                    else
                    {
                        pdfTable = pdfDocument.NewTable(table.DataFont, rowCount, visibleColumnCount, cellPadding);
                    }

                    pdfTable.pdfPage = page;

                    System.Data.DataTable dt = new System.Data.DataTable();
                    for (int i = 0; i < table.Columns.Length; i++)
                    {
                        if (table.Columns[i].Width > 0)
                        {
                            if (table.Columns[i].FormatMask == "Image")
                            {
                                dt.Columns.Add("", typeof(byte[]));
                            }
                            else
                            {
                                dt.Columns.Add("", typeof(System.String));
                            }
                        }
                    }

                    for (int i = 0; i < data.Rows.Count; i++)
                    {
                        if (data.Rows[i].RowError == "Subtotal")
                        {
                            object[] rowData = new object[visibleColumnCount];
                            int      cnt     = 0;
                            for (int j = 0; j < table.Columns.Length; j++)
                            {
                                if (table.Columns[j].Width > 0)
                                {
                                    rowData[cnt] = table.Subtotals[j];
                                    cnt++;
                                }
                            }

                            dt.Rows.Add(rowData);
                        }
                        else
                        {
                            object[] rowData = new object[visibleColumnCount];
                            int      cnt     = 0;
                            for (int j = 0; j < table.Columns.Length; j++)
                            {
                                if (table.Columns[j].Width > 0)
                                {
                                    if (table.Columns[j].FormatMask == null || table.Columns[j].FormatMask == String.Empty)
                                    {
                                        rowData[cnt] = String.Format("{0}", data.Rows[i][j]);
                                    }
                                    else if (table.Columns[j].FormatMask == "Image")
                                    {
                                        rowData[cnt] = data.Rows[i][j] is byte[] ? data.Rows[i][j] : null;
                                    }
                                    else
                                    {
                                        rowData[cnt] = String.Format("{0:" + table.Columns[j].FormatMask + "}", data.Rows[i][j]);
                                    }
                                    cnt++;
                                }
                            }
                            dt.Rows.Add(rowData);
                        }
                    }

                    if (table.DrawEmptyRows)
                    {
                        for (int i = 0; i < table.Height / table.CellHeight; i++)
                        {
                            dt.Rows.Add(dt.NewRow());
                        }
                    }

                    pdfTable.ImportDataTable(dt);


                    pdfTable.SetRowHeight(Convert(table.CellHeight));

                    pdfTable.VisibleHeaders = table.DrawHeader;
                    pdfTable.HeadersRow.SetRowHeight(Convert(table.CellHeight));
                    pdfTable.HeadersRow.SetColors(table.HeaderFontColor, table.HeaderBackgroundColor);
                    pdfTable.HeadersRow.SetFont(table.HeaderFont);

                    pdfTable.SetColors(table.DataFontColor, table.BackgroundColor);
                    pdfTable.SetBorders(table.BorderColor, 1, BorderType.CompleteGrid);
                    //pdfTable.SetBorders(table.BorderColor, (table.BorderColor == Color.Transparent ? 0 : 1), BorderType.CompleteGrid);


                    int[] columnWidths = new int[visibleColumnCount];
                    int   tableWidth   = 0;
                    int   count        = 0;
                    for (int i = 0; i < table.Columns.Length; i++)
                    {
                        if (table.Columns[i].Width > 0)
                        {
                            columnWidths[count] = (int)Convert(table.Columns[i].Width);
                            tableWidth         += columnWidths[count];

                            string columnName = table.Columns[i].Label == String.Empty || table.Columns[i].Label == "" ? " " : table.Columns[i].Label;
                            pdfTable.HeadersRow[count].SetContent(columnName);

                            Com.Delta.Print.Engine.Pdf.HorizontalAlignment columnAlignment = GetColumnContentAlignment(table.Columns[i].Alignment);
                            pdfTable.HeadersRow[count].SetContentAlignment(columnAlignment, VerticalAlignment.Middle);
                            pdfTable.Columns[count].SetContentAlignment(columnAlignment, VerticalAlignment.Middle);

                            count++;
                        }
                    }
                    pdfTable.SetColumnsWidth(columnWidths);


                    ArrayList alterRows = table.AlterRows;
                    for (int i = 0; i < data.Rows.Count; i++)
                    {
                        if (table.AlternateBackColor && i % 2 == 1)
                        {
                            pdfTable.Rows[i].SetBackgroundColor(table.AlternatingBackColor);
                        }

                        if (alterRows != null && alterRows.Count > 0)
                        {
                            if (alterRows.Contains(data.Rows[i]) && i < pdfTable.Rows.Length)
                            {
                                pdfTable.Rows[i].SetForegroundColor(table.AlterDataColor);
                                pdfTable.Rows[i].SetBackgroundColor(table.AlterDataBackColor);
                            }
                        }
                    }


                    if (table.DrawEmptyRows && table.AlternateBackColor)
                    {
                        for (int i = data.Rows.Count; i < table.Height / table.CellHeight; i++)
                        {
                            if (i % 2 == 1)
                            {
                                pdfTable.Rows[i].SetBackgroundColor(table.AlternatingBackColor);
                            }
                        }
                    }



                    if (table.HasSubtotals)
                    {
                        for (int i = 0; i < data.Rows.Count; i++)
                        {
                            if (data.Rows[i].RowError == "Subtotal" && i < pdfTable.Rows.Length)
                            {
                                pdfTable.Rows[i].SetForegroundColor(table.SubtotalsColor);
                            }
                        }
                    }

                    PdfTablePage tablePage = pdfTable.CreateTablePage(new PdfArea(pdfDocument, Convert(table.Bounds.X), Convert(table.Bounds.Y), tableWidth, Convert(table.Bounds.Height)));

                    page.Add(tablePage);

                    foreach (PdfImage image in pdfTable.Images.Keys)
                    {
                        RectangleF area = (RectangleF)pdfTable.Images[image];
                        page.Add(image, area.X, area.Y, 0.72 * area.Width, 0.72 * area.Height);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
コード例 #5
0
        public Boolean addTable(PdfDocument myPdfDocument, DataTable t, int rows)
        {
            try
            {
                // Now we create a Table of 100 lines, 6 columns and 4 points of Padding.
                PdfTable myPdfTable = myPdfDocument.NewTable(new Font("Verdana", 10), rows, TotalColumns, 4);

                // Importing datas from the datatables... (also column names for the headers!)
                myPdfTable.ImportDataTable(t);

                // Sets the format for correct date-time representation
                //myPdfTable.Columns[2].SetContentFormat("{0:dd/MM/yyyy}");

                // Now we set our Graphic Design: Colors and Borders...
                myPdfTable.HeadersRow.SetColors(Color.White, Color.Black);
                myPdfTable.SetColors(Color.Black, Color.White, Color.White);
                myPdfTable.SetBorders(Color.Black, 1, BorderType.CompleteGrid);
                //White
                // Now we set some alignment... for the whole table and then, for a column.
                myPdfTable.SetContentAlignment(ContentAlignment.MiddleLeft);
                myPdfTable.Columns[0].SetContentAlignment(ContentAlignment.MiddleRight);
                myPdfTable.Columns[1].SetContentAlignment(ContentAlignment.MiddleRight);

                // With just one method we can set the proportional width of the columns.
                // It's a "percentage like" assignment, but the sum can be different from 100.

                myPdfTable.SetContentAlignment(ContentAlignment.MiddleRight);
                myPdfTable.SetColumnsWidth(new int[] { 15, 100, 15 });
                myPdfTable.Columns[1].SetContentAlignment(ContentAlignment.MiddleLeft);



                while (!myPdfTable.AllTablePagesCreated)
                {
                    // we create a new page to put the generation of the new TablePage:
                    PdfPage      newPdfPage      = myPdfDocument.NewPage();
                    PdfTablePage newPdfTablePage = null;


                    newPdfTablePage = myPdfTable.CreateTablePage(new PdfArea(myPdfDocument, 18, 140, 560, 670));
                    System.Drawing.PointF pointS  = new PointF(0, 115);
                    System.Drawing.PointF pointE1 = new PointF(1000, 115);
                    System.Drawing.PointF pointE2 = new PointF(595, 115);
                    // nice thing: we can put all the objects in the following lines, so we can have
                    // a great control of layer sequence...


                    PdfImage LogoImage = myPdfDocument.NewImage(@"logo.jpg");
                    newPdfPage.Add(newPdfTablePage);
                    newPdfPage.Add(LogoImage, 15, 10, 100);
                    PdfLine pdfline = new PdfLine(myPdfDocument, pointS, pointE2, Color.Black, 1);
                    newPdfPage.Add(pdfline);

                    newPdfPage.SaveToDocument();
                    pdf_table_no++;
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
            // Finally we save the docuement...
        }
コード例 #6
0
        public Stream GenerateSelectedTasksPDF(IEnumerable <SelectedTask> selectedTasks, ReportInfo reportInfo)
        {
            int            countSelectedTasks = selectedTasks.Count();
            int            totalNoiseDosage   = selectedTasks.Sum(x => x.Percentage);
            NoiseLevelEnum noiseLevelEnum     = _noiseLevelService.CalculateNoiseLevelEnum(totalNoiseDosage);
            Color          noiseLevelColor    = GetColorForNoiseLevel(noiseLevelEnum);
            DataTable      dataTable          = GenerateDataTable(selectedTasks);


            // Starting instantiate the document.
            // Remember to set the Docuement Format. In this case, we specify width and height.
            PdfDocument myPdfDocument = new PdfDocument(PdfDocumentFormat.A4_Horizontal);

            // Now we create a Table with lines likt the number of selected tasks, 6 columns and 4 points of Padding.
            PdfTable myPdfTable = myPdfDocument.NewTable(new Font("Verdana", 12), countSelectedTasks, 6, 4);

            // Importing datas from the datatables... (also column names for the headers!)
            myPdfTable.ImportDataTable(dataTable);

            // Now we set our Graphic Design: Colors and Borders...
            myPdfTable.HeadersRow.SetColors(Color.FromRgb(255, 255, 255), Color.FromRgb(0, 0, 255));
            myPdfTable.SetColors(Color.FromRgb(0, 0, 0), Color.FromRgb(255, 255, 255), Color.FromRgb(0, 255, 255));
            myPdfTable.SetBorders(Color.FromRgb(0, 0, 0), 1, BorderType.CompleteGrid);

            // With just one method we can set the proportional width of the columns.
            // It's a "percentage like" assignment, but the sum can be different from 100.
            myPdfTable.SetColumnsWidth(new int[] { 90, 25, 45, 20, 20, 10 });

            // Now we set some alignment... for the whole table and then, for a column.
            myPdfTable.SetContentAlignment(ContentAlignment.MiddleCenter);
            foreach (PdfColumn pdfColumn in myPdfTable.Columns)
            {
                pdfColumn.SetContentAlignment(ContentAlignment.MiddleLeft);
            }

            // Here we start the loop to generate the table...
            while (!myPdfTable.AllTablePagesCreated)
            {
                // we create a new page to put the generation of the new TablePage:
                PdfPage newPdfPage = myPdfDocument.NewPage();

                // LAKHA
                PdfArea      pdfArea   = new PdfArea(myPdfDocument, 48, 95, 750, 670);
                PdfTablePage taskTable = myPdfTable.CreateTablePage(pdfArea);

                // we also put a Label
                PdfTextArea reportTitle = new PdfTextArea(new Font("Verdana", 26, FontStyle.Bold), Color.FromRgb(0, 0, 0)
                                                          , new PdfArea(myPdfDocument, 48, 20, 595, 60), ContentAlignment.TopLeft, ReportResource.ReportTitle);

                // LAKHA - Status
                PdfTextArea statusText = new PdfTextArea(new Font("Verdana", 14, FontStyle.Bold), Color.FromRgb(0, 0, 0)
                                                         , new PdfArea(myPdfDocument, 48, taskTable.CellArea(taskTable.LastRow, 6 - 1).BottomRightCornerY + 10, 595, 60), ContentAlignment.TopLeft,
                                                         _noiseLevelService.GetNoiseLevelStatusText(noiseLevelEnum));

                // LAKHA - Total prosent
                PdfRectangle summaryBackground = new PdfArea(myPdfDocument, 635, taskTable.CellArea(taskTable.LastRow, 6 - 1).BottomRightCornerY + 10, 165, 45).ToRectangle(noiseLevelColor, noiseLevelColor);
                PdfTextArea  summary           = new PdfTextArea(new Font("Verdana", 26, FontStyle.Bold), Color.FromRgb(0, 0, 0)
                                                                 , new PdfArea(myPdfDocument, 640, taskTable.CellArea(taskTable.LastRow, 6 - 1).BottomRightCornerY + 20, 595, 60), ContentAlignment.TopLeft,
                                                                 string.Format(ReportResource.TotalPercentageFormatString, totalNoiseDosage));

                // nice thing: we can put all the objects in the following lines, so we can have
                // a great control of layer sequence...
                newPdfPage.Add(taskTable);
                newPdfPage.Add(reportTitle);
                newPdfPage.Add(statusText);
                newPdfPage.Add(summaryBackground);
                newPdfPage.Add(summary);

                // Info from report input window
                PdfTextArea reportPlant = new PdfTextArea(new Font("Verdana", 12, FontStyle.Bold), Color.FromRgb(0, 0, 0)
                                                          , new PdfArea(myPdfDocument, 48, 50, 595, 60), ContentAlignment.TopLeft, string.Format(ReportResource.PlantFormatString, reportInfo.Plant));
                PdfTextArea reportCreatedBy = new PdfTextArea(new Font("Verdana", 12, FontStyle.Bold), Color.FromRgb(0, 0, 0)
                                                              , new PdfArea(myPdfDocument, 650, 50, 595, 60), ContentAlignment.TopLeft, string.Format(ReportResource.UserFormatString, reportInfo.CreatedBy));

                PdfTextArea reportProfession = new PdfTextArea(new Font("Verdana", 12, FontStyle.Bold), Color.FromRgb(0, 0, 0)
                                                               , new PdfArea(myPdfDocument, 48, 65, 595, 60), ContentAlignment.TopLeft, string.Format(ReportResource.ProfessionFormatString, reportInfo.Group));
                PdfTextArea reportDate = new PdfTextArea(new Font("Verdana", 12, FontStyle.Bold), Color.FromRgb(0, 0, 0)
                                                         , new PdfArea(myPdfDocument, 650, 65, 595, 60), ContentAlignment.TopLeft, string.Format(ReportResource.DateFormatString, (reportInfo.Date.HasValue) ? reportInfo.Date.Value.ToString("dd.MM.yyyy") : string.Empty));

                PdfTextArea reportComment = new PdfTextArea(new Font("Verdana", 12, FontStyle.Bold), Color.FromRgb(0, 0, 0)
                                                            , new PdfArea(myPdfDocument, 48, 80, 700, 60), ContentAlignment.TopLeft, string.Format(ReportResource.CommentFormatString, reportInfo.Comment));

                newPdfPage.Add(reportPlant);
                newPdfPage.Add(reportCreatedBy);
                newPdfPage.Add(reportProfession);
                newPdfPage.Add(reportDate);
                newPdfPage.Add(reportComment);


                // LAKHA - Add footnotes...
                const int widthOfFootnote = 750;
                Font      footnoteFont    = new Font("Verdana", 9, FontStyle.Regular);
                double    posY            = statusText.PdfArea.BottomRightCornerY + 3;

                foreach (string footNoteText in reportInfo.Footnotes)
                {
                    int heightOfFootnote = 10;

                    if (footNoteText.Length > 380)
                    {
                        heightOfFootnote = heightOfFootnote * 3;
                    }
                    else if (footNoteText.Length > 160)
                    {
                        heightOfFootnote = heightOfFootnote * 2;
                    }

                    PdfArea     pdfAreaForText = new PdfArea(myPdfDocument, 48, posY, widthOfFootnote, heightOfFootnote);
                    PdfTextArea footNote       = new PdfTextArea(footnoteFont, Color.FromRgb(0, 0, 0), pdfAreaForText, ContentAlignment.TopLeft, string.Format("* {0}", footNoteText));
                    newPdfPage.Add(footNote);

                    posY = footNote.PdfArea.BottomRightCornerY + 2;
                }

                // we save each generated page before start rendering the next.
                newPdfPage.SaveToDocument();
            }


            // Finally we save the docuement...
            Stream memoryStream = new MemoryStream();

            myPdfDocument.SaveToStream(memoryStream);
            memoryStream.Seek(0, SeekOrigin.Begin);

            return(memoryStream);
        }
コード例 #7
0
        private void AddTablaResultadosPorBloque(PdfPage page, int yPos)
        {
            var text = new PdfTextArea(
                Function_Library.FontTitulo,
                Color.Black,
                new PdfArea(pdfDocument, 80, yPos, 450, 20),
                ContentAlignment.MiddleCenter,
                PDF_Resources.Title_ResultadosXBloque);

            page.Add(text);

            var dataTable = new DataTable();

            dataTable.Columns.Add(PDF_Resources.Header_MEDIDAS);
            for (int i = 0; i < 7; i++)
            {
                dataTable.Columns.Add(i.ToString());
            }

            // Para que se entienda que no se incluyen los ultimos dos parámetros
            int rows    = (datos.TNotaciones.Parametros.Length - 2) + 2;
            int columns = dataTable.Columns.Count;

            PdfTable myPdfTable = pdfDocument.NewTable(Function_Library.FontTexto11, rows, columns, 3);

            DataRow row = dataTable.NewRow();

            row[PDF_Resources.Header_MEDIDAS] = PDF_Resources.Header_MEDIDAS;
            row["0"] = PDF_Resources.Header_BLOQUES;
            dataTable.Rows.Add(row);

            row = dataTable.NewRow();
            for (int i = 0; i < 7; i++)
            {
                row[i.ToString()] = (i + 1).ToString();
            }
            dataTable.Rows.Add(row);

            for (int i = 2; i < (datos.TNotaciones.Parametros.Length - 2) + 2; i++)
            {
                row = dataTable.NewRow();
                row[PDF_Resources.Header_MEDIDAS] = datos.TNotaciones.Parametros[i - 2];
                for (int j = 0; j < 7; j++)
                {
                    row[j.ToString()] = datos.PercentilesXbloque[j, i - 2];
                }
                dataTable.Rows.Add(row);
            }

            myPdfTable.ImportDataTable(dataTable);
            myPdfTable.VisibleHeaders = false;
            myPdfTable.SetColors(Color.Black, Color.White);
            myPdfTable.SetBorders(Color.Black, 1, BorderType.CompleteGrid);
            myPdfTable.SetColumnsWidth(new[] { 37, 9, 9, 9, 9, 9, 9, 9 });
            myPdfTable.SetContentAlignment(ContentAlignment.MiddleCenter);
            myPdfTable.Columns[0].SetContentAlignment(ContentAlignment.MiddleLeft);
            myPdfTable.Rows[0][0].SetContentAlignment(ContentAlignment.MiddleCenter);
            myPdfTable.Rows[0].SetBackgroundColor(Color.FromArgb(242, 242, 242));
            myPdfTable.Rows[1].SetBackgroundColor(Color.FromArgb(242, 242, 242));
            myPdfTable.Rows[0][0].RowSpan = 2;
            myPdfTable.Rows[0][1].ColSpan = 7;
            PdfTablePage newPdfTablePage = myPdfTable.CreateTablePage(new PdfArea(pdfDocument, 75, yPos + 40, 450, 420));

            page.Add(newPdfTablePage);

            var footText = new PdfTextArea(
                Function_Library.FontTexto10,
                Color.Black,
                new PdfArea(pdfDocument, 80, yPos + 180, 450, 80),
                ContentAlignment.MiddleLeft,
                PDF_Resources.FootNote_Puntuaciones);

            page.Add(footText);
        }