protected void btnGenerarReporte_Click(object sender, EventArgs e)
        {
            MemoryStream ms = new MemoryStream();

            PdfWriter   pw  = new PdfWriter(ms);
            PdfDocument pdf = new PdfDocument(pw);
            Document    doc = new Document(pdf, PageSize.A4);

            doc.SetMargins(75, 35, 70, 35);
            string pathLogo = Server.MapPath("../Imagenes/Care Monitor.jpg");

            iText.Layout.Element.Image img = new iText.Layout.Element.Image(iText.IO.Image.ImageDataFactory.Create(pathLogo));

            pdf.AddEventHandler(PdfDocumentEvent.START_PAGE, new HeaderEventHandler(img));


            iText.Layout.Element.Table tabla = new iText.Layout.Element.Table(1).UseAllAvailableWidth();
            Cell cell = new Cell().Add(new Paragraph("Reporte de Bitácora").SetFontSize(14)
                                       .SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER)
                                       .SetBorder(Border.NO_BORDER));

            tabla.AddCell(cell);

            doc.Add(tabla);

            iText.Layout.Style styleCell = new iText.Layout.Style()
                                           .SetBackgroundColor(ColorConstants.LIGHT_GRAY)
                                           .SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);

            iText.Layout.Element.Table _tabla = new iText.Layout.Element.Table(4).UseAllAvailableWidth();
            Cell _cell = new Cell().Add(new Paragraph("Fecha"));

            _tabla.AddHeaderCell(_cell.AddStyle(styleCell));
            _cell = new Cell().Add(new Paragraph("Usuario"));
            _tabla.AddHeaderCell(_cell.AddStyle(styleCell));
            _cell = new Cell().Add(new Paragraph("Tipo"));
            _tabla.AddHeaderCell(_cell.AddStyle(styleCell));
            _cell = new Cell().Add(new Paragraph("Acción"));
            _tabla.AddHeaderCell(_cell.AddStyle(styleCell));



            List <BE.Bitacora> listaBitacora = (List <BE.Bitacora>)Session["ListaBitacora"];

            foreach (BE.Bitacora bit in listaBitacora)
            {
                _cell = new Cell().Add(new Paragraph(bit.Fecha.ToString("g")));
                _tabla.AddCell(_cell);
                _cell = new Cell().Add(new Paragraph(bit.Usuario));
                _tabla.AddCell(_cell);
                _cell = new Cell().Add(new Paragraph(bit.Tipo));
                _tabla.AddCell(_cell);
                _cell = new Cell().Add(new Paragraph(bit.Accion));
                _tabla.AddCell(_cell);
            }

            doc.Add(_tabla);

            doc.Close();

            byte[] bytesStream = ms.ToArray();
            ms = new MemoryStream();
            ms.Write(bytesStream, 0, bytesStream.Length);
            ms.Position = 0;

            Response.AddHeader("content-disposition", "inline;filename=Reporte.pdf");
            Response.ContentType = "application/octectstream";
            Response.BinaryWrite(bytesStream);
            Response.End();
        }
 public HeaderEventHandler(iText.Layout.Element.Image img)
 {
     Img = img;
 }
        protected void btnGenerarReporte_Click(object sender, EventArgs e)
        {
            MemoryStream ms = new MemoryStream();

            PdfWriter   pw  = new PdfWriter(ms);
            PdfDocument pdf = new PdfDocument(pw);
            Document    doc = new Document(pdf, PageSize.A4);

            doc.SetMargins(75, 35, 70, 35);
            string pathLogo = Server.MapPath("../Imagenes/Care Monitor.jpg");

            iText.Layout.Element.Image img = new iText.Layout.Element.Image(iText.IO.Image.ImageDataFactory.Create(pathLogo));

            pdf.AddEventHandler(PdfDocumentEvent.START_PAGE, new HeaderEventHandler(img));

            BE.Usuario usu = (BE.Usuario)Session["UsuarioEnSesion"];

            iText.Layout.Element.Table tabla = new iText.Layout.Element.Table(1).UseAllAvailableWidth();
            Cell cell = new Cell().Add(new Paragraph("Mediciones de " + usu.Nombre + " " + usu.Apellido).SetFontSize(14)
                                       .SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER)
                                       .SetBorder(Border.NO_BORDER));

            tabla.AddCell(cell);

            doc.Add(tabla);

            iText.Layout.Style styleCell = new iText.Layout.Style()
                                           .SetBackgroundColor(ColorConstants.LIGHT_GRAY)
                                           .SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);

            iText.Layout.Element.Table _tabla = new iText.Layout.Element.Table(5).UseAllAvailableWidth();
            Cell _cell = new Cell().Add(new Paragraph("Fecha"));

            _tabla.AddHeaderCell(_cell.AddStyle(styleCell));
            _cell = new Cell().Add(new Paragraph("Tipo"));
            _tabla.AddHeaderCell(_cell.AddStyle(styleCell));
            _cell = new Cell().Add(new Paragraph("Valor"));
            _tabla.AddHeaderCell(_cell.AddStyle(styleCell));
            _cell = new Cell().Add(new Paragraph("Máximo"));
            _tabla.AddHeaderCell(_cell.AddStyle(styleCell));
            _cell = new Cell().Add(new Paragraph("Mínimo"));
            _tabla.AddHeaderCell(_cell.AddStyle(styleCell));



            foreach (BE.Medicion bit in ListaMediciones)
            {
                _cell = new Cell().Add(new Paragraph(bit.Fecha.ToString("g")));
                _tabla.AddCell(_cell);
                _cell = new Cell().Add(new Paragraph(bit.Tipo.Nombre));
                _tabla.AddCell(_cell);
                if (bit.Valor < bit.Tipo.MinimoMasculino || bit.Valor > bit.Tipo.MaximoMasculino)
                {
                    _cell = new Cell().Add(new Paragraph(bit.Valor.ToString()));
                    _tabla.AddCell(_cell.SetBackgroundColor(ColorConstants.RED));
                }
                else
                {
                    _cell = new Cell().Add(new Paragraph(bit.Valor.ToString()));
                    _tabla.AddCell(_cell);
                }

                _cell = new Cell().Add(new Paragraph(bit.Tipo.MaximoMasculino.ToString()));
                _tabla.AddCell(_cell);
                _cell = new Cell().Add(new Paragraph(bit.Tipo.MinimoMasculino.ToString()));
                _tabla.AddCell(_cell);
            }

            doc.Add(_tabla);

            doc.Close();

            byte[] bytesStream = ms.ToArray();
            ms = new MemoryStream();
            ms.Write(bytesStream, 0, bytesStream.Length);
            ms.Position = 0;

            Response.AddHeader("content-disposition", "inline;filename=Reporte.pdf");
            Response.ContentType = "application/octectstream";
            Response.BinaryWrite(bytesStream);
            Response.End();
        }