public void PDFESTADOCERO() { Buscadores bus = new Buscadores(); var doc = new iTextSharp.text.Document(PageSize.A4); string path = Server.MapPath("~"); PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(path + "/Taller.pdf", FileMode.Create)); doc.Open(); //Cabecera BaseFont bfntHead = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font fntHead = new iTextSharp.text.Font(bfntHead, 16, 1, iTextSharp.text.BaseColor.GREEN.Darker()); Paragraph prgHeading = new Paragraph(); prgHeading.Alignment = 1; prgHeading.Add(new Chunk("Taller de Reparaciones".ToUpper(), fntHead)); doc.Add(prgHeading); doc.Add(Chunk.NEWLINE); //Generado By Paragraph prgGeneratedBY = new Paragraph(); BaseFont btnAuthor = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font fntAuthor = new iTextSharp.text.Font(btnAuthor, 12, 2, iTextSharp.text.BaseColor.BLACK); prgGeneratedBY.Alignment = Element.ALIGN_RIGHT; prgGeneratedBY.Add(new Chunk("Generado por: " + LogEmpleado.nombreyapellido, fntAuthor)); //Agregar LOG Empleado prgGeneratedBY.Add(new Chunk("\nFecha : " + DateTime.Now.ToShortDateString(), fntAuthor)); prgGeneratedBY.Add(new Chunk("\nN° de Orden : " + OrdenActual.id_orden, fntAuthor)); doc.Add(prgGeneratedBY); Paragraph p = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, iTextSharp.text.BaseColor.BLACK, Element.ALIGN_LEFT, 1))); doc.Add(p); //Espacio doc.Add(new Chunk("\n", fntHead)); //Datos Paragraph Datos = new Paragraph(); BaseFont bfntDatos = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font fntDatos = new iTextSharp.text.Font(bfntDatos, 12, 0, iTextSharp.text.BaseColor.BLACK); Datos.Alignment = Element.ALIGN_CENTER; Datos.Add(new Chunk("\nPatente: " + OrdenActual.vehiculo.patente + " Modelo:" + OrdenActual.vehiculo.modelo.nombre + " Marca: " + OrdenActual.vehiculo.modelo.marca.nombre, fntDatos)); doc.Add(Datos); //Espacio doc.Add(new Chunk("\n", fntHead)); foreach (servicio oservicio in LSUSO) { doc.Add(p); Paragraph Dato = new Paragraph(); Dato.Alignment = Element.ALIGN_LEFT; Dato.Add(new Chunk("\nServicio: " + oservicio.detalle, fntDatos)); doc.Add(Dato); //Espacio doc.Add(new Chunk("\n", fntHead)); //Creo una tabla DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[4] { new DataColumn("Codigo"), new DataColumn("Detalle"), new DataColumn("Marca"), new DataColumn("Cantidad") }); //nombre de las columnas List <stock> Lstock = bus.Lstockuso(oservicio.id_servicios.ToString()); foreach (stock ostock in Lstock) { dt.Rows.Add(ostock.codigo, ostock.detalle, ostock.marca, ostock.cantidad); //Agrego las filas a la tabla } //Tabla PdfPTable table = new PdfPTable(dt.Columns.Count); for (int i = 0; i < dt.Columns.Count; i++) { string cellText = Server.HtmlDecode(dt.Columns[i].ColumnName); PdfPCell cell = new PdfPCell(); cell.Phrase = new Phrase(cellText, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 10, 1, new BaseColor(System.Drawing.ColorTranslator.FromHtml("#000000")))); cell.BackgroundColor = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#C8C8C8")); cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.PaddingBottom = 5; table.AddCell(cell); } for (int i = 0; i < dt.Rows.Count; i++) { for (int j = 0; j < dt.Columns.Count; j++) { table.AddCell(dt.Rows[i][j].ToString()); } } doc.Add(table); //Espacio doc.Add(new Chunk("\n", fntHead)); } doc.Close(); Page.ClientScript.RegisterStartupScript(this.GetType(), "OpenWindow", "window.open('Taller.pdf','_newtab');", true); }