示例#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
        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...
        }
        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);
        }
示例#6
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);
        }