public iText.Layout.Element.Table getTable(PdfDocumentEvent docEvent) { float[] cellWidth = { 20f, 80f }; iText.Layout.Element.Table tableEvent = new iText.Layout.Element.Table(UnitValue.CreatePercentArray(cellWidth)).UseAllAvailableWidth(); iText.Layout.Style styleCell = new iText.Layout.Style() .SetBorder(Border.NO_BORDER); iText.Layout.Style styleText = new iText.Layout.Style() .SetTextAlignment(TextAlignment.RIGHT).SetFontSize(10f); Cell cell = new Cell().Add(Img.SetAutoScale(true)); tableEvent.AddCell(cell .AddStyle(styleCell) .SetTextAlignment(TextAlignment.LEFT)); PdfFont bold = PdfFontFactory.CreateFont(StandardFonts.TIMES_BOLD); cell = new Cell() .Add(new Paragraph("CareMonitor")).SetFont(bold) .Add(new Paragraph("Fecha de Emisión: " + DateTime.Now.ToShortDateString())) .AddStyle(styleText).AddStyle(styleCell); tableEvent.AddCell(cell); return(tableEvent); }
public static async Task CrearGraficosIndividualesEnPdf_7(Document doc, ListCollectionView lista, DateTime fecha) { await Task.Run(() => { int indice = 1; double num = 1; foreach (object obj in lista) { double valor = num / lista.Count * 100; App.Global.ValorBarraProgreso = valor; num++; Grafico g = obj as Grafico; if (g == null) { continue; } if (indice > 1) { doc.Add(new AreaBreak(AreaBreakType.NEXT_PAGE)); } // Creamos la tabla de título //Table tablaTitulo = PdfTools.GetTablaTitulo($"{fecha:dd - MMMM - yyyy}".ToUpper(), App.Global.CentroActual.ToString().ToUpper()); string textoTitulo = $"{fecha:dd - MMMM - yyyy}\n{App.Global.CentroActual}".ToUpper(); iText.Layout.Style estiloTitulo = new iText.Layout.Style(); estiloTitulo.SetFontSize(12).SetBold(); estiloTitulo.SetMargins(0, 0, 6, 0); estiloTitulo.SetPadding(0); estiloTitulo.SetWidth(UnitValue.CreatePercentValue(100)); estiloTitulo.SetBorder(iText.Layout.Borders.Border.NO_BORDER); Table tablaTitulo = InformesServicio.GetTablaEncabezadoSindicato(textoTitulo, estiloTitulo); // TODO: Creamos la tabla de informacion string textoGrafico = "Gráfico: " + (string)cnvNumGrafico.Convert(g.Numero, null, null, null) + " Turno: " + g.Turno.ToString("0"); string textoValoracion = "Valoración: " + (string)cnvHora.Convert(g.Valoracion, null, VerValores.NoCeros, null); Table tablaInformacion = PdfTools.GetTablaTitulo(textoGrafico, textoValoracion); tablaInformacion.SetWidth(UnitValue.CreatePercentValue(100)); tablaInformacion.SetFontSize(9).SetBold(); // Creamos la tabla de valoraciones Table tablaValoraciones = GetGraficoIndividual(g); // TODO: Creamos la tabla de valores string textoValores = ""; if (g.Desayuno > 0) { textoValores += String.Format("Desayuno: {0:0.00} ", g.Desayuno); } if (g.Comida > 0) { textoValores += String.Format("Comida: {0:0.00} ", g.Comida); } if (g.Cena > 0) { textoValores += String.Format("Cena: {0:0.00} ", g.Cena); } if (g.PlusCena > 0) { textoValores += String.Format("Plus Cena: {0:0.00} ", g.PlusCena); } if (g.PlusLimpieza) { textoValores += "Limp. "; } if (g.PlusPaqueteria) { textoValores += "Paqu. "; } string textoHoras = $"Trab: {(string)cnvHora.Convert(g.Trabajadas, null, null, null)} " + $"Acum: {(string)cnvHora.Convert(g.Acumuladas, null, null, null)} " + $"Noct: {(string)cnvHora.Convert(g.Nocturnas, null, null, null)}"; Table tablaValores = PdfTools.GetTablaTitulo(textoValores, textoHoras); tablaValores.SetWidth(UnitValue.CreatePercentValue(100)); tablaValores.SetFontSize(9).SetBold(); // Añadimos las tablas al documento doc.Add(tablaTitulo); doc.Add(tablaInformacion); doc.Add(tablaValoraciones); doc.Add(tablaValores); indice++; } }); }
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(); }
// ==================================================================================================== #region MÉTODOS PRIVADOS (ITEXT 7) // ==================================================================================================== private static Table GetTablaGraficos(ListCollectionView listaGraficos, DateTime fecha) { // Fuente a utilizar en la tabla. PdfFont arial = PdfFontFactory.CreateFont("c:/windows/fonts/calibri.ttf", true); // Estilo de la tabla. iText.Layout.Style estiloTabla = new iText.Layout.Style(); estiloTabla.SetTextAlignment(TextAlignment.CENTER) .SetVerticalAlignment(VerticalAlignment.MIDDLE) .SetMargins(0, 0, 0, 0) .SetPaddings(0, 0, 0, 0) .SetWidth(UnitValue.CreatePercentValue(100)) .SetFont(arial) .SetFontSize(8); // Estilo titulos iText.Layout.Style estiloTitulos = new iText.Layout.Style(); estiloTitulos.SetBold() .SetBorder(iText.Layout.Borders.Border.NO_BORDER) .SetFontSize(14); // Estilo de las celdas de encabezado. iText.Layout.Style estiloEncabezados = new iText.Layout.Style(); estiloEncabezados.SetBackgroundColor(new DeviceRgb(112, 173, 71)) .SetBold() .SetFontSize(8); // Estilo de las celdas de izq. iText.Layout.Style estiloIzq = new iText.Layout.Style(); estiloIzq.SetBorderLeft(new SolidBorder(1)); // Estilo de las celdas de med. iText.Layout.Style estiloMed = new iText.Layout.Style(); estiloMed.SetBorderTop(new SolidBorder(1)) .SetBorderBottom(new SolidBorder(1)); // Estilo de las celdas de der. iText.Layout.Style estiloDer = new iText.Layout.Style(); estiloDer.SetBorderRight(new SolidBorder(1)); // Creamos la tabla float[] ancho = new float[] { 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3 }; Table tabla = new Table(UnitValue.CreatePercentArray(ancho)); // Asignamos el estilo a la tabla. tabla.AddStyle(estiloTabla); string textoEncabezado = $"GRÁFICOS\n{fecha:dd - MMMM - yyyy} ({App.Global.CentroActual})".ToUpper(); Table tablaEncabezado = InformesServicio.GetTablaEncabezadoSindicato(textoEncabezado); tabla.AddHeaderCell(new Cell(1, 17).Add(tablaEncabezado).AddStyle(estiloTitulos)); // Añadimos las celdas de encabezado. tabla.AddHeaderCell(new Cell().Add(new Paragraph("Número")).AddStyle(estiloEncabezados).AddStyle(estiloIzq).AddStyle(estiloMed)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Turno")).AddStyle(estiloEncabezados).AddStyle(estiloMed)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Inicio")).AddStyle(estiloEncabezados).AddStyle(estiloMed)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Final")).AddStyle(estiloEncabezados).AddStyle(estiloMed)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Ini. Partido")).AddStyle(estiloEncabezados).AddStyle(estiloMed)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Fin. Partido")).AddStyle(estiloEncabezados).AddStyle(estiloMed)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Valoracion")).AddStyle(estiloEncabezados).AddStyle(estiloMed)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Trabajadas")).AddStyle(estiloEncabezados).AddStyle(estiloMed)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Dif.")).AddStyle(estiloEncabezados).AddStyle(estiloMed)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Acumuladas")).AddStyle(estiloEncabezados).AddStyle(estiloMed)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Nocturnas")).AddStyle(estiloEncabezados).AddStyle(estiloMed)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Desayuno")).AddStyle(estiloEncabezados).AddStyle(estiloMed)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Comida")).AddStyle(estiloEncabezados).AddStyle(estiloMed)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Cena")).AddStyle(estiloEncabezados).AddStyle(estiloMed)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Plus Cena")).AddStyle(estiloEncabezados).AddStyle(estiloMed)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Limpieza")).AddStyle(estiloEncabezados).AddStyle(estiloMed)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Paquetería")).AddStyle(estiloEncabezados).AddStyle(estiloDer).AddStyle(estiloMed)); // Añadimos las celdas con los calendarios. int indice = 1; foreach (Object obj in listaGraficos) { Grafico g = obj as Grafico; if (g == null) { continue; } // Estilo Fondo Alternativo iText.Layout.Style estiloFondo = new iText.Layout.Style().SetBackgroundColor(ColorConstants.WHITE); if (indice % 2 == 0) { estiloFondo.SetBackgroundColor(new DeviceRgb(226, 239, 218)); } indice++; // Estilo Valoracion Diferente iText.Layout.Style estiloValDif = new iText.Layout.Style(); if (g.DiferenciaValoracion.Ticks != 0) { estiloValDif.SetFontColor(new DeviceRgb(255, 20, 147)); } // Escribimos el grafico. tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvNumGrafico.Convert(g.Numero, null, null, null)}")) .AddStyle(estiloIzq).AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{g.Turno.ToString("0")}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.Inicio, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.Final, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.InicioPartido, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.FinalPartido, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.Valoracion, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo).AddStyle(estiloValDif)); tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.Trabajadas, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo).AddStyle(estiloValDif)); tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.DiferenciaValoracion, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo).AddStyle(estiloValDif)); tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.Acumuladas, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.Nocturnas, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvDecimal.Convert(g.Desayuno, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvDecimal.Convert(g.Comida, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvDecimal.Convert(g.Cena, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvDecimal.Convert(g.PlusCena, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(g.PlusLimpieza ? "X" : "")}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(g.PlusPaqueteria ? "X" : "")}")) .AddStyle(estiloDer).AddStyle(estiloFondo)); } // Ponemos los bordes de la tabla. tabla.SetBorderBottom(new SolidBorder(1)); // Devolvemos la tabla. return(tabla); }
private static Table GetGraficoIndividual(Grafico grafico) { // Fuente a utilizar en la tabla. PdfFont arial = PdfFontFactory.CreateFont("c:/windows/fonts/calibri.ttf", true); // Estilo de la tabla. iText.Layout.Style estiloTabla = new iText.Layout.Style(); estiloTabla.SetTextAlignment(TextAlignment.CENTER) .SetVerticalAlignment(VerticalAlignment.MIDDLE) .SetMargins(0, 0, 0, 0) .SetPaddings(0, 0, 0, 0) .SetWidth(UnitValue.CreatePercentValue(100)) .SetFont(arial) .SetFontSize(8); // Estilo de las celdas de encabezado. iText.Layout.Style estiloEncabezados = new iText.Layout.Style(); estiloEncabezados.SetBackgroundColor(new DeviceRgb(112, 173, 71)) .SetBold() .SetFontSize(8); // Creamos la tabla float[] ancho = new float[] { 10, 10, 60, 10, 10 }; Table tabla = new Table(UnitValue.CreatePercentArray(ancho)); // Asignamos el estilo a la tabla. tabla.AddStyle(estiloTabla); // Añadimos las celdas de encabezado. tabla.AddHeaderCell(new Cell().Add(new Paragraph("Inicio")).AddStyle(estiloEncabezados)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Línea")).AddStyle(estiloEncabezados)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Descripción")).AddStyle(estiloEncabezados)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Final")).AddStyle(estiloEncabezados)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Tiempo")).AddStyle(estiloEncabezados)); // Añadimos los datos del gráfico int indice = 1; foreach (var valoracion in grafico.ListaValoraciones) { // Estilo Fondo Alternativo iText.Layout.Style estiloFondo = new iText.Layout.Style().SetBackgroundColor(ColorConstants.WHITE); if (indice % 2 == 0) { estiloFondo.SetBackgroundColor(new DeviceRgb(226, 239, 218)); } indice++; // Escribimos el grafico. tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(valoracion.Inicio, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(valoracion.Linea == 0 ? "" : valoracion.Linea.ToString())}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{valoracion.Descripcion}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(valoracion.Final, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(valoracion.Tiempo, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo)); } // Ponemos los bordes de la tabla. tabla.GetHeader().SetBorder(new SolidBorder(1)); tabla.SetBorder(new SolidBorder(1)); // Devolvemos la tabla. return(tabla); }
private void Btn_reporte_Click(object sender, RoutedEventArgs e) { string ruta = @"C:\Reportes Restaurante\Reportes Boletas"; if (!Directory.Exists(ruta)) { Console.WriteLine("Creando el directorio: {0}", ruta); DirectoryInfo direc = Directory.CreateDirectory(ruta); } else { Console.WriteLine("El directorio ya existe, no se ha realizado ninguna acción", ruta); } //var folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var exportfile = System.IO.Path.Combine(ruta, "reporte.pdf"); UsuarioBLL usrBLL = new UsuarioBLL(); //DataTable dt = usrBLL.Getdatoplato(); PdfWriter pw = new PdfWriter(exportfile); PdfDocument pdfDoc = new PdfDocument(pw); Document doc = new Document(pdfDoc, PageSize.LETTER); doc.SetMargins(75, 30, 75, 30); Table tb = new Table(1).UseAllAvailableWidth(); Cell cell = new Cell().Add(new Paragraph("Reporte").SetFontSize(14) .SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER) .SetBorder(Border.NO_BORDER) .SetFontColor(ColorConstants.BLUE)); tb.AddCell(cell); doc.Add(tb); iText.Layout.Style stylecell = new iText.Layout.Style().SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); Table tb2 = new Table(8).UseAllAvailableWidth(); Cell cell2 = new Cell().Add(new Paragraph("#")); tb2.AddCell(cell2.AddStyle(stylecell)); cell2 = new Cell().Add(new Paragraph("Fecha")); tb2.AddCell(cell2.AddStyle(stylecell)); cell2 = new Cell().Add(new Paragraph("Medio de Pago")); tb2.AddCell(cell2.AddStyle(stylecell)); cell2 = new Cell().Add(new Paragraph("Sub Total")); tb2.AddCell(cell2.AddStyle(stylecell)); cell2 = new Cell().Add(new Paragraph("Descuentos")); tb2.AddCell(cell2.AddStyle(stylecell)); cell2 = new Cell().Add(new Paragraph("Total")); tb2.AddCell(cell2.AddStyle(stylecell)); cell2 = new Cell().Add(new Paragraph("Mesa")); tb2.AddCell(cell2.AddStyle(stylecell)); cell2 = new Cell().Add(new Paragraph("Rut Cliente")); tb2.AddCell(cell2.AddStyle(stylecell)); int tot = Total(dt); int sub = subtotal(dt); int desc = descuentos(dt); int filas = dt.Rows.Count; int contador = 0; foreach (DataRow row in dt.Rows) { cell2 = new Cell().Add(new Paragraph(row["ID"].ToString())); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph(row["FECHA"].ToString())); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph(row["MEDIO DE PAGO"].ToString())); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph(row["SUB TOTAL"].ToString())); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph(row["DESCUENTOS"].ToString())); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph(row["TOTAL"].ToString())); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph(row["MESA"].ToString())); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph(row["CLIENTE"].ToString())); tb2.AddCell(cell2); int aux = dt.Rows.Count; if (contador == aux - 1) { cell2 = new Cell().Add(new Paragraph("")); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph("")); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph("")); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph("" + sub)); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph("" + desc)); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph("" + tot)); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph("")); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph("")); tb2.AddCell(cell2); } else { } contador++; } doc.Add(tb2); doc.Close(); MessageBox.Show("creado"); }
private Table CreateHeaders(Document document, Style headerStyle, string title) { Bitmap bmpImage = Properties.Resources.SICE; ImageConverter converter = new ImageConverter(); Byte[] byteImage = (byte[])converter.ConvertTo(bmpImage, typeof(byte[])); ImageData imageData = ImageDataFactory.Create(byteImage); iText.Layout.Element.Image pdfImg = new iText.Layout.Element.Image(imageData); pdfImg.SetHeight(150); pdfImg.SetWidth(200); pdfImg.SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER); document.Add(pdfImg); PdfFont font = PdfFontFactory.CreateFont(FontConstants.TIMES_BOLD); Style titleStyle = new Style(); titleStyle.SetFont(font).SetFontSize(24); titleStyle.SetBold(); document.Add(new Paragraph(title).AddStyle(titleStyle)); Table table = new Table(37); table.AddHeaderCell("Document"); table.AddHeaderCell("I 1").AddStyle(headerStyle); table.AddHeaderCell("I 3").AddStyle(headerStyle); table.AddHeaderCell("I 2").AddStyle(headerStyle); table.AddHeaderCell("I 4").AddStyle(headerStyle); table.AddHeaderCell("I 5").AddStyle(headerStyle); table.AddHeaderCell("I 6").AddStyle(headerStyle); table.AddHeaderCell("I 7").AddStyle(headerStyle); table.AddHeaderCell("I 8").AddStyle(headerStyle); table.AddHeaderCell("I 9").AddStyle(headerStyle); table.AddHeaderCell("I 10").AddStyle(headerStyle); table.AddHeaderCell("I 11").AddStyle(headerStyle); table.AddHeaderCell("I 12").AddStyle(headerStyle); table.AddHeaderCell("I 13").AddStyle(headerStyle); table.AddHeaderCell("I 14").AddStyle(headerStyle); table.AddHeaderCell("I 15").AddStyle(headerStyle); table.AddHeaderCell("I 16").AddStyle(headerStyle); table.AddHeaderCell("I 17").AddStyle(headerStyle); table.AddHeaderCell("Database").AddStyle(headerStyle); table.AddHeaderCell("I 1").AddStyle(headerStyle); table.AddHeaderCell("I 3").AddStyle(headerStyle); table.AddHeaderCell("I 2").AddStyle(headerStyle); table.AddHeaderCell("I 4").AddStyle(headerStyle); table.AddHeaderCell("I 5").AddStyle(headerStyle); table.AddHeaderCell("I 6").AddStyle(headerStyle); table.AddHeaderCell("I 7").AddStyle(headerStyle); table.AddHeaderCell("I 8").AddStyle(headerStyle); table.AddHeaderCell("I 9").AddStyle(headerStyle); table.AddHeaderCell("I 10").AddStyle(headerStyle); table.AddHeaderCell("I 11").AddStyle(headerStyle); table.AddHeaderCell("I 12").AddStyle(headerStyle); table.AddHeaderCell("I 13").AddStyle(headerStyle); table.AddHeaderCell("I 14").AddStyle(headerStyle); table.AddHeaderCell("I 15").AddStyle(headerStyle); table.AddHeaderCell("I 16").AddStyle(headerStyle); table.AddHeaderCell("I 17").AddStyle(headerStyle); table.AddHeaderCell("Result").AddStyle(headerStyle); return(table); }
private void ExportComparison(object title) { // Must have write permissions to the path folder FileInfo file = new FileInfo(titlePDF.ToString() + ".pdf"); file.Delete(); var fileStream = file.Create(); fileStream.Close(); PdfDocument pdfdoc = new PdfDocument(new PdfWriter(file)); PdfFont font = PdfFontFactory.CreateFont(StandardFonts.TIMES_BOLD); PdfFont cellFont = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN); PdfFont OKFont = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN); PdfFont NOKFont = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN); Style headerStyle = new Style(); headerStyle.SetFont(font).SetFontSize(11); headerStyle.SetBold(); Style cellStyle = new Style(); cellStyle.SetFont(cellFont).SetFontSize(10); Style OKStyle = new Style(); OKStyle.SetFont(OKFont).SetFontSize(10); OKStyle.SetFontColor(ColorConstants.GREEN, 1); Style NOKStyle = new Style(); NOKStyle.SetFont(NOKFont).SetFontSize(10); NOKStyle.SetFontColor(ColorConstants.RED, 1); pdfdoc.SetDefaultPageSize(PageSize.A2.Rotate()); pdfdoc.SetTagged(); using (Document document = new Document(pdfdoc)) { iText.Layout.Element.Cell cell; Table table = CreateHeaders(document, headerStyle, title.ToString()); for (int i = 0; i < documentationImportList.Count; i++) { cell = new iText.Layout.Element.Cell(1, 1); cell.Add(new Paragraph(documentationImportList[i].deviceName)).AddStyle(cellStyle); table.AddCell(cell); foreach (string iconName in documentationImportList[i].iconNames) { // documentationImportList[i].iconNames; if (File.Exists(imagesDir + "icono" + iconName + ".png")) { ImageData imageData = ImageDataFactory.Create(imagesDir + "icono" + iconName + ".png"); iText.Layout.Element.Image pdfImg = new iText.Layout.Element.Image(imageData); pdfImg.SetHeight(32); pdfImg.SetWidth(32); table.AddCell(pdfImg); } else { table.AddCell("X"); } } for (int j = documentationImportList[i].iconNames.Count; j < 17; j++) { table.AddCell(""); } DeviceIconGroup databaseItem = databaseImportList.Find(x => x.deviceName.Equals(documentationImportList[i].deviceName)); cell = new iText.Layout.Element.Cell(1, 1); cell.Add(new Paragraph(databaseItem.deviceName)).AddStyle(cellStyle); table.AddCell(cell);//.AddStyle(cellStyle); foreach (string iconName in databaseItem.iconNames) { if (File.Exists(imagesDir + "icono" + iconName + ".png")) { // documentationImportList[i].iconNames; ImageData imageData = ImageDataFactory.Create(imagesDir + "icono" + iconName + ".png"); iText.Layout.Element.Image pdfImg = new iText.Layout.Element.Image(imageData); pdfImg.SetHeight(32); pdfImg.SetWidth(32); table.AddCell(pdfImg); } else { table.AddCell("X"); } } for (int j = 19 + databaseItem.iconNames.Count; j < 36; j++) { table.AddCell(""); } if (documentationImportList[i].IsEqualTo(databaseItem)) { cell = new iText.Layout.Element.Cell(1, 1); cell.Add(new Paragraph("OK")).AddStyle(OKStyle); table.AddCell(cell); } else { cell = new iText.Layout.Element.Cell(1, 1); cell.Add(new Paragraph("NOK")).AddStyle(NOKStyle); table.AddCell(cell); } this.Dispatcher.Invoke( new UpdatePgBar(this.updatePgBar), new object[] { (double.Parse(i.ToString()) / double.Parse(documentationImportList.Count().ToString())) * 100 } ); } //Create table document.Add(table); this.Dispatcher.Invoke( new FinishReading(EnableWindowOptions), new object[] { } ); } }
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(); }
private void Button_Click_1(object sender, RoutedEventArgs e) { /*string path = @"c:\pdf"; * if (Directory.Exists(path)) * { * Console.WriteLine("That path exists already."); * } * * // Try to create the directory. * DirectoryInfo di = Directory.CreateDirectory(path); * Console.WriteLine("The directory was created successfully at {0}.", Directory.GetCreationTime(path));*/ string ruta = @"C:\Reportes Restaurante\Reportes Platos"; if (!Directory.Exists(ruta)) { Console.WriteLine("Creando el directorio: {0}", ruta); DirectoryInfo direc = Directory.CreateDirectory(ruta); } else { Console.WriteLine("El directorio ya existe, no se ha realizado ninguna acción", ruta); } //var folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var exportfile = System.IO.Path.Combine(ruta, "reporte.pdf"); UsuarioBLL usrBLL = new UsuarioBLL(); DataTable dt = usrBLL.Getdatoplato(); PdfWriter pw = new PdfWriter(exportfile); PdfDocument pdfDoc = new PdfDocument(pw); Document doc = new Document(pdfDoc, PageSize.LETTER); doc.SetMargins(75, 30, 75, 30); Table tb = new Table(1).UseAllAvailableWidth(); Cell cell = new Cell().Add(new Paragraph("Reporte").SetFontSize(14) .SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER) .SetBorder(Border.NO_BORDER) .SetFontColor(ColorConstants.BLUE)); tb.AddCell(cell); doc.Add(tb); iText.Layout.Style stylecell = new iText.Layout.Style().SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); Table tb2 = new Table(5).UseAllAvailableWidth(); Cell cell2 = new Cell().Add(new Paragraph("#")); tb2.AddCell(cell2.AddStyle(stylecell)); cell2 = new Cell().Add(new Paragraph("Nombre")); tb2.AddCell(cell2.AddStyle(stylecell)); cell2 = new Cell().Add(new Paragraph("Precio")); tb2.AddCell(cell2.AddStyle(stylecell)); cell2 = new Cell().Add(new Paragraph("Categoria")); tb2.AddCell(cell2.AddStyle(stylecell)); cell2 = new Cell().Add(new Paragraph("habilitado")); tb2.AddCell(cell2.AddStyle(stylecell)); foreach (DataRow row in dt.Rows) { cell2 = new Cell().Add(new Paragraph(row["ID_PLATO"].ToString())); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph(row["NOMBRE_PLATO"].ToString())); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph(row["PRECIO"].ToString())); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph(row["CATEGORIA"].ToString())); tb2.AddCell(cell2); cell2 = new Cell().Add(new Paragraph(row["HABILITADO"].ToString())); tb2.AddCell(cell2); } doc.Add(tb2); doc.Close(); MessageBox.Show("creado"); }