public static MemoryStream memStream(string Doc) { MemoryStream memoryStream = new System.IO.MemoryStream(); StringReader srdr = new StringReader(Doc); Document pdfDoc = new Document(PageSize.A4, 40, 40, 20, 35); HTMLWorker hparse = new HTMLWorker(pdfDoc); PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, memoryStream); //Define the page number PageEventHelper pageEventHelper = new PageEventHelper(); pdfWriter.PageEvent = pageEventHelper; // Define the page header pageEventHelper.Title = ""; pageEventHelper.HeaderFont = FontFactory.GetFont(BaseFont.COURIER_BOLD, 10, Font.BOLD); pageEventHelper.HeaderLeft = ""; pageEventHelper.HeaderRight = ""; pdfDoc.Open(); hparse.Parse(srdr); pdfWriter.CloseStream = false; pdfDoc.Close(); pdfWriter.Close(); return(memoryStream); }
protected void Page_Load(object sender, EventArgs e) { if (Request["id"] == null) { Response.Redirect("./Dashboard.aspx"); } entryForm = null; try { //EntryId = new Guid(GeneralFunction.StringDecryption(Request.QueryString["Id"])); EntryId = new Guid(Request.QueryString["Id"]); if (Request["temp"] != null) { if (Session["Entry-" + EntryId.ToString() + Request["skey"]] == null) { return; } entryForm = (EntryForm)Session["Entry-" + EntryId.ToString() + Request["skey"]]; //HttpContext.Current.Session.Remove("Entry-" + EntryId.ToString() + Request["skey"]); } else { entryForm = EntryForm.GetEntryForm(Guid.Empty, EntryId); } entry = Entry.GetEntry(EntryId); } catch { Response.Redirect("./Dashboard.aspx"); } MemoryStream memoryStream = new System.IO.MemoryStream(); StringReader srdr = new StringReader(GetDocument()); Document pdfDoc = new Document(PageSize.A4, 40, 40, 20, 35); HTMLWorker hparse = new HTMLWorker(pdfDoc); PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, memoryStream); //Define the page number PageEventHelper pageEventHelper = new PageEventHelper(); pdfWriter.PageEvent = pageEventHelper; // Define the page header pageEventHelper.Title = ""; pageEventHelper.HeaderFont = FontFactory.GetFont(BaseFont.COURIER_BOLD, 10, Font.BOLD); pageEventHelper.HeaderLeft = ""; pageEventHelper.HeaderRight = ""; pdfDoc.Open(); hparse.Parse(srdr); pdfWriter.CloseStream = false; pdfDoc.Close(); pdfWriter.Close(); Response.ContentType = "application/pdf"; memoryStream.WriteTo(Response.OutputStream); memoryStream.Close(); }
public async Task <IActionResult> activosEnManteJefePdf(int idJefe) { Document doc = new Document(PageSize.Letter); doc.SetMargins(40f, 40f, 40f, 40f); MemoryStream ms = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(doc, ms); //Instanciamos la clase para el paginado y la fecha de impresión var pe = new PageEventHelper(); writer.PageEvent = pe; doc.AddAuthor("Asgard"); doc.AddTitle("Reporte activos en mantenimiento"); doc.Open(); //Inicia cuerpo del reporte //Estilo y fuente personalizada BaseFont fuente = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1250, true); iTextSharp.text.Font parrafo = new iTextSharp.text.Font(fuente, 12f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); BaseFont fuente2 = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, true); iTextSharp.text.Font parrafo2 = new iTextSharp.text.Font(fuente2, 10f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); BaseFont fuente3 = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, true); iTextSharp.text.Font parrafo3 = new iTextSharp.text.Font(fuente3, 15f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); BaseFont fuente4 = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1250, true); iTextSharp.text.Font parrafo4 = new iTextSharp.text.Font(fuente4, 11f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); //Para las celdas BaseFont fuente5 = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, true); iTextSharp.text.Font parrafo5 = new iTextSharp.text.Font(fuente5, 10f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); //Encabezado using (BDAcaassAFContext bd = new BDAcaassAFContext()) { CooperativaAF oCooperativaAF = new CooperativaAF(); Cooperativa oCooperativa = bd.Cooperativa.Where(p => p.Dhabilitado == 1).First(); oCooperativaAF.idcooperativa = oCooperativa.IdCooperativa; oCooperativaAF.nombre = oCooperativa.Nombre; oCooperativaAF.descripcion = oCooperativa.Descripcion; //Se agrega el encabezado var tbl1 = new PdfPTable(new float[] { 11f, 89f }) { WidthPercentage = 100f }; tbl1.AddCell(new PdfPCell(new Phrase(" ", parrafo2)) { Border = 0, Rowspan = 2 }); tbl1.AddCell(new PdfPCell(new Phrase(oCooperativa.Descripcion.ToUpper(), parrafo2)) { Border = 0, HorizontalAlignment = 1 }); tbl1.AddCell(new PdfPCell(new Phrase(oCooperativa.Nombre.ToUpper(), parrafo3)) { Border = 0, HorizontalAlignment = 1 }); doc.Add(tbl1); doc.Add(new Phrase("\n")); } doc.Add(new Phrase("\n")); //Línea separadora Chunk linea = new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(1f, 100f, BaseColor.Black, Element.ALIGN_CENTER, 1f)); doc.Add(linea); doc.Add(new Paragraph("REPORTE DE ACTIVOS EN MANTENIMIENTO", parrafo) { Alignment = Element.ALIGN_CENTER }); //Espacio en blanco doc.Add(Chunk.Newline); //Agregamos una tabla var tbl = new PdfPTable(new float[] { 25f, 40f, 40f, 40f }) { WidthPercentage = 100f }; var c1 = new PdfPCell(new Phrase("CÓDIGO", parrafo2)); var c2 = new PdfPCell(new Phrase("DESCRIPCIÓN", parrafo2)); var c3 = new PdfPCell(new Phrase("RAZONES DE MANTENIMIENTO", parrafo2)); var c4 = new PdfPCell(new Phrase("PERÍODO DE MANTENIMIENTO", parrafo2)); //Agregamos a la tabla las celdas tbl.AddCell(c1); tbl.AddCell(c2); tbl.AddCell(c3); tbl.AddCell(c4); //Extraemos de la base y llenamos las celdas using (BDAcaassAFContext bd = new BDAcaassAFContext()) { Empleado oempleado = bd.Empleado.Where(p => p.IdEmpleado == idJefe).FirstOrDefault(); AreaDeNegocio oarea = bd.AreaDeNegocio.Where(p => p.IdAreaNegocio == oempleado.IdAreaDeNegocio).FirstOrDefault(); IEnumerable <BienesSolicitadosMttoAF> lista = (from bienMtto in bd.BienMantenimiento join activo in bd.ActivoFijo on bienMtto.IdBien equals activo.IdBien join solicitud in bd.SolicitudMantenimiento on bienMtto.IdSolicitud equals solicitud.IdSolicitud join resposable in bd.Empleado on activo.IdResponsable equals resposable.IdEmpleado join area in bd.AreaDeNegocio on resposable.IdAreaDeNegocio equals area.IdAreaNegocio // join informe in bd.InformeMantenimiento // on bienMtto.IdMantenimiento equals informe.IdMantenimiento where activo.EstadoActual == 3 && bienMtto.Estado == 1 && area.IdAreaNegocio == oarea.IdAreaNegocio //ELEMENTO 2 LISTA select new BienesSolicitadosMttoAF { idBien = activo.IdBien, idmantenimiento = bienMtto.IdMantenimiento, estadoActual = (int)activo.EstadoActual, Codigo = activo.CorrelativoBien, Descripcion = activo.Desripcion, Periodo = bienMtto.PeriodoMantenimiento, Razon = bienMtto.RazonMantenimiento, fechacadena = solicitud.Fecha == null ? " " : ((DateTime)solicitud.Fecha).ToString("dd-MM-yyyy"), }).ToList(); foreach (var activosmante in lista) { c1.Phrase = new Phrase(activosmante.Codigo, parrafo5); c2.Phrase = new Phrase(activosmante.Descripcion, parrafo5); c3.Phrase = new Phrase(activosmante.Razon, parrafo5); c4.Phrase = new Phrase(activosmante.Periodo, parrafo5); //Agregamos a la tabla tbl.AddCell(c1); tbl.AddCell(c2); tbl.AddCell(c3); tbl.AddCell(c4); } //INICIO DE ADICIÓN DE LOGO CooperativaAF oCooperativaAF = new CooperativaAF(); Cooperativa oCooperativa = bd.Cooperativa.Where(p => p.Dhabilitado == 1).First(); oCooperativaAF.idcooperativa = oCooperativa.IdCooperativa; try { iTextSharp.text.Image logo = null; logo = iTextSharp.text.Image.GetInstance(oCooperativa.Logo.ToString()); logo.Alignment = iTextSharp.text.Image.ALIGN_LEFT; logo.Border = iTextSharp.text.Rectangle.NO_BORDER; logo.BorderColor = iTextSharp.text.BaseColor.White; logo.ScaleToFit(170f, 100f); float ancho = logo.Width; float alto = logo.Height; float proporcion = alto / ancho; logo.ScaleAbsoluteWidth(80); logo.ScaleAbsoluteHeight(80 * proporcion); logo.SetAbsolutePosition(40f, 695f); doc.Add(logo); } catch (DocumentException dex) { //log exception here } //FIN DE ADICIÓN DE LOGO } doc.Add(tbl); writer.Close(); doc.Close(); ms.Seek(0, SeekOrigin.Begin); return(File(ms, "application/pdf")); }
public async Task <IActionResult> historialmantenimientopdf(int idbien) { Document doc = new Document(PageSize.Letter); doc.SetMargins(40f, 40f, 40f, 40f); MemoryStream ms = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(doc, ms); //Instanciamos la clase para el paginado y la fecha de impresión var pe = new PageEventHelper(); writer.PageEvent = pe; doc.AddAuthor("Asgard"); doc.AddTitle("Reporte historial mantenimiento"); doc.Open(); //Inicia cuerpo del reporte //Estilo y fuente personalizada BaseFont fuente = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1250, true); iTextSharp.text.Font parrafo = new iTextSharp.text.Font(fuente, 12f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); BaseFont fuente2 = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, true); iTextSharp.text.Font parrafo2 = new iTextSharp.text.Font(fuente2, 11f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); BaseFont fuente3 = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, true); iTextSharp.text.Font parrafo3 = new iTextSharp.text.Font(fuente3, 15f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); BaseFont fuente4 = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1250, true); iTextSharp.text.Font parrafo4 = new iTextSharp.text.Font(fuente4, 11f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); //Para las celdas BaseFont fuente5 = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, true); iTextSharp.text.Font parrafo5 = new iTextSharp.text.Font(fuente5, 10f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); //Fuente para tarjeta BaseFont fuente6 = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, true); iTextSharp.text.Font parrafo6 = new iTextSharp.text.Font(fuente2, 9f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); BaseFont fuente7 = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1250, true); iTextSharp.text.Font parrafo7 = new iTextSharp.text.Font(fuente, 9f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); BaseFont fuente8 = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, true); iTextSharp.text.Font parrafo8 = new iTextSharp.text.Font(fuente2, 9f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); //Encabezado using (BDAcaassAFContext bd = new BDAcaassAFContext()) { CooperativaAF oCooperativaAF = new CooperativaAF(); Cooperativa oCooperativa = bd.Cooperativa.Where(p => p.Dhabilitado == 1).First(); oCooperativaAF.idcooperativa = oCooperativa.IdCooperativa; oCooperativaAF.nombre = oCooperativa.Nombre; oCooperativaAF.descripcion = oCooperativa.Descripcion; //Se agrega el encabezado var tbl1 = new PdfPTable(new float[] { 11f, 89f }) { WidthPercentage = 100f }; tbl1.AddCell(new PdfPCell(new Phrase(" ", parrafo2)) { Border = 0, Rowspan = 2 }); tbl1.AddCell(new PdfPCell(new Phrase(oCooperativa.Descripcion.ToUpper(), parrafo2)) { Border = 0, HorizontalAlignment = 1 }); tbl1.AddCell(new PdfPCell(new Phrase(oCooperativa.Nombre.ToUpper(), parrafo3)) { Border = 0, HorizontalAlignment = 1 }); doc.Add(tbl1); doc.Add(new Phrase("\n")); } doc.Add(new Phrase("\n")); //Línea separadora Chunk linea = new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(1f, 100f, BaseColor.Black, Element.ALIGN_CENTER, 1f)); doc.Add(linea); doc.Add(new Paragraph("REPORTE HISTORIAL DE MANTENIMIENTO ", parrafo) { Alignment = Element.ALIGN_CENTER }); //Espacio en blanco doc.Add(Chunk.Newline); //Extraemos de la base y llenamos las celdas using (BDAcaassAFContext bd = new BDAcaassAFContext()) { InformeMatenimientoAF odatos = new InformeMatenimientoAF(); ActivoFijo oActivo = bd.ActivoFijo.Where(p => p.IdBien == idbien).First(); odatos.descripcion = oActivo.Desripcion; odatos.codigo = oActivo.CorrelativoBien; Empleado oempleado = bd.Empleado.Where(p => p.IdEmpleado == oActivo.IdResponsable).First(); AreaDeNegocio oArea = bd.AreaDeNegocio.Where(p => p.IdAreaNegocio == oempleado.IdAreaDeNegocio).First(); odatos.encargado = oempleado.Nombres + " " + oempleado.Apellidos; odatos.areadenegocio = oArea.Nombre; // return odatos; //Cuerpo de la tarjeta var tbl1 = new PdfPTable(new float[] { 4f, 7f, 5f, 7f }) { WidthPercentage = 100f }; tbl1.AddCell(new PdfPCell(new Phrase("Correlativo: ", parrafo6)) { Border = 0, Rowspan = 2 }); tbl1.AddCell(new PdfPCell(new Phrase(odatos.codigo, parrafo7)) { Border = 0 }); tbl1.AddCell(new PdfPCell(new Phrase("Descripción de activo: ", parrafo6)) { Border = 0, Rowspan = 2 }); tbl1.AddCell(new PdfPCell(new Phrase(odatos.descripcion, parrafo7)) { Border = 0 }); var tbl2 = new PdfPTable(new float[] { 4f, 7f, 5f, 7f }) { WidthPercentage = 100f }; tbl2.AddCell(new PdfPCell(new Phrase("Encargado actual: ", parrafo6)) { Border = 0, Rowspan = 2 }); tbl2.AddCell(new PdfPCell(new Phrase(odatos.encargado, parrafo7)) { Border = 0 }); tbl2.AddCell(new PdfPCell(new Phrase("Área de negocio actual: ", parrafo6)) { Border = 0, Rowspan = 2 }); tbl2.AddCell(new PdfPCell(new Phrase(odatos.areadenegocio, parrafo7)) { Border = 0 }); doc.Add(tbl1); doc.Add(Chunk.Newline); doc.Add(tbl2); doc.Add(Chunk.Newline); //Tabla de transacciones // doc.Add(new Paragraph("TABLA HISTORIAL DE TRASPASOS", parrafo2) { Alignment = Element.ALIGN_CENTER }); //Agregamos una tabla //Agregamos una tabla var tbl = new PdfPTable(new float[] { 25f, 30f, 25f, 30f, 20f, 40f }) { WidthPercentage = 100f }; var c1 = new PdfPCell(new Phrase("FECHA", parrafo2)); var c2 = new PdfPCell(new Phrase("TÉCNICO", parrafo2)); var c3 = new PdfPCell(new Phrase("MANO DE OBRA", parrafo2)); var c4 = new PdfPCell(new Phrase("MATERIALES", parrafo2)); var c5 = new PdfPCell(new Phrase("COSTO TOTAL", parrafo2)); var c6 = new PdfPCell(new Phrase("DESCRIPCIÓN", parrafo2)); //Agregamos a la tabla las celdas tbl.AddCell(c1); tbl.AddCell(c2); tbl.AddCell(c3); tbl.AddCell(c4); tbl.AddCell(c5); tbl.AddCell(c6); IEnumerable <InformeMatenimientoAF> lista = (from tecnico in bd.Tecnicos join informemante in bd.InformeMantenimiento on tecnico.IdTecnico equals informemante.IdTecnico join bienmante in bd.BienMantenimiento on informemante.IdMantenimiento equals bienmante.IdMantenimiento join bienes in bd.ActivoFijo on bienmante.IdBien equals bienes.IdBien where bienes.IdBien == idbien //&& informemante.Estado == 0 || informemante.Estado == 2 || informemante.Estado == 1 orderby bienes.CorrelativoBien select new InformeMatenimientoAF { idinformematenimiento = informemante.IdInformeMantenimiento, idBien = bienes.IdBien, idmantenimiento = (int)informemante.IdMantenimiento, fechacadena = informemante.Fecha == null ? " " : ((DateTime)informemante.Fecha).ToString("dd-MM-yyyy"), nombretecnico = tecnico.Nombre, codigo = bienes.CorrelativoBien, descripcion = informemante.Descripcion, costomateriales = (double)informemante.CostoMateriales, costomo = (double)informemante.CostoMo, costototal = (double)informemante.CostoTotal, bienes = bienes.Desripcion }).ToList(); foreach (var historialmante in lista) { c1.Phrase = new Phrase(historialmante.fechacadena, parrafo5); c2.Phrase = new Phrase(historialmante.nombretecnico, parrafo5); c3.Phrase = new Phrase("$" + historialmante.costomo.ToString(), parrafo5); c4.Phrase = new Phrase("$" + historialmante.costomateriales.ToString(), parrafo5); c5.Phrase = new Phrase("$" + historialmante.costototal.ToString(), parrafo5); c6.Phrase = new Phrase(historialmante.descripcion, parrafo5); //Agregamos a la tabla tbl.AddCell(c1); tbl.AddCell(c2); tbl.AddCell(c3); tbl.AddCell(c4); tbl.AddCell(c5); tbl.AddCell(c6); } doc.Add(tbl); //INICIO DE ADICIÓN DE LOGO CooperativaAF oCooperativaAF = new CooperativaAF(); Cooperativa oCooperativa = bd.Cooperativa.Where(p => p.Dhabilitado == 1).First(); oCooperativaAF.idcooperativa = oCooperativa.IdCooperativa; try { iTextSharp.text.Image logo = null; logo = iTextSharp.text.Image.GetInstance(oCooperativa.Logo.ToString()); logo.Alignment = iTextSharp.text.Image.ALIGN_LEFT; logo.Border = iTextSharp.text.Rectangle.NO_BORDER; logo.BorderColor = iTextSharp.text.BaseColor.White; logo.ScaleToFit(170f, 100f); float ancho = logo.Width; float alto = logo.Height; float proporcion = alto / ancho; logo.ScaleAbsoluteWidth(80); logo.ScaleAbsoluteHeight(80 * proporcion); logo.SetAbsolutePosition(40f, 695f); doc.Add(logo); } catch (DocumentException dex) { //log exception here } //FIN DE ADICIÓN DE LOGO } writer.Close(); doc.Close(); ms.Seek(0, SeekOrigin.Begin); return(File(ms, "application/pdf")); }
public async Task <IActionResult> solicitudesmantenimientopdf() { Document doc = new Document(PageSize.Letter); doc.SetMargins(40f, 40f, 40f, 40f); MemoryStream ms = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(doc, ms); //Instanciamos la clase para el paginado y la fecha de impresión var pe = new PageEventHelper(); writer.PageEvent = pe; doc.AddAuthor("Asgard"); doc.AddTitle("Reporte solicitudes de mantenimiento"); doc.Open(); //Inicia cuerpo del reporte //Estilo y fuente personalizada BaseFont fuente = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1250, true); iTextSharp.text.Font parrafo = new iTextSharp.text.Font(fuente, 12f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); BaseFont fuente2 = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, true); iTextSharp.text.Font parrafo2 = new iTextSharp.text.Font(fuente2, 11f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); BaseFont fuente3 = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, true); iTextSharp.text.Font parrafo3 = new iTextSharp.text.Font(fuente3, 15f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); BaseFont fuente4 = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1250, true); iTextSharp.text.Font parrafo4 = new iTextSharp.text.Font(fuente4, 11f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); //Para las celdas BaseFont fuente5 = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, true); iTextSharp.text.Font parrafo5 = new iTextSharp.text.Font(fuente5, 10f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); //Encabezado using (BDAcaassAFContext bd = new BDAcaassAFContext()) { CooperativaAF oCooperativaAF = new CooperativaAF(); Cooperativa oCooperativa = bd.Cooperativa.Where(p => p.Dhabilitado == 1).First(); oCooperativaAF.idcooperativa = oCooperativa.IdCooperativa; oCooperativaAF.nombre = oCooperativa.Nombre; oCooperativaAF.descripcion = oCooperativa.Descripcion; //Se agrega el encabezado var tbl1 = new PdfPTable(new float[] { 11f, 89f }) { WidthPercentage = 100f }; tbl1.AddCell(new PdfPCell(new Phrase(" ", parrafo2)) { Border = 0, Rowspan = 2 }); tbl1.AddCell(new PdfPCell(new Phrase(oCooperativa.Descripcion.ToUpper(), parrafo2)) { Border = 0, HorizontalAlignment = 1 }); tbl1.AddCell(new PdfPCell(new Phrase(oCooperativa.Nombre.ToUpper(), parrafo3)) { Border = 0, HorizontalAlignment = 1 }); doc.Add(tbl1); doc.Add(new Phrase("\n")); } doc.Add(new Phrase("\n")); //Línea separadora Chunk linea = new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(1f, 100f, BaseColor.Black, Element.ALIGN_CENTER, 1f)); doc.Add(linea); doc.Add(new Paragraph("REPORTE DE SOLICITUDES DE MANTENIMIENTO", parrafo) { Alignment = Element.ALIGN_CENTER }); //Espacio en blanco doc.Add(Chunk.Newline); //Agregamos una tabla var tbl = new PdfPTable(new float[] { 25f, 30f, 50f }) { WidthPercentage = 100f }; var c1 = new PdfPCell(new Phrase("FOLIO", parrafo2)); var c2 = new PdfPCell(new Phrase("FECHA DE SOLICITUD", parrafo2)); var c3 = new PdfPCell(new Phrase("DESCRIPCIÓN", parrafo2)); //Agregamos a la tabla las celdas tbl.AddCell(c1); tbl.AddCell(c2); tbl.AddCell(c3); //Extraemos de la base y llenamos las celdas using (BDAcaassAFContext bd = new BDAcaassAFContext()) { IEnumerable <SolicitudMantenimientoPAF> lista = (from solicitud in bd.SolicitudMantenimiento where solicitud.Estado == 1 select new SolicitudMantenimientoPAF { idsolicitud = solicitud.IdSolicitud, folio = solicitud.Folio, descripcion = solicitud.Descripcion, fechacadena = solicitud.Fecha == null ? " " : ((DateTime)solicitud.Fecha).ToString("dd-MM-yyyy") }).ToList(); foreach (var solicitudmante in lista) { c1.Phrase = new Phrase(solicitudmante.folio, parrafo5); c2.Phrase = new Phrase(solicitudmante.fechacadena, parrafo5); c3.Phrase = new Phrase(solicitudmante.descripcion, parrafo5); //Agregamos a la tabla tbl.AddCell(c1); tbl.AddCell(c2); tbl.AddCell(c3); } //INICIO DE ADICIÓN DE LOGO CooperativaAF oCooperativaAF = new CooperativaAF(); Cooperativa oCooperativa = bd.Cooperativa.Where(p => p.Dhabilitado == 1).First(); oCooperativaAF.idcooperativa = oCooperativa.IdCooperativa; try { iTextSharp.text.Image logo = null; logo = iTextSharp.text.Image.GetInstance(oCooperativa.Logo.ToString()); logo.Alignment = iTextSharp.text.Image.ALIGN_LEFT; logo.Border = iTextSharp.text.Rectangle.NO_BORDER; logo.BorderColor = iTextSharp.text.BaseColor.White; logo.ScaleToFit(170f, 100f); float ancho = logo.Width; float alto = logo.Height; float proporcion = alto / ancho; logo.ScaleAbsoluteWidth(80); logo.ScaleAbsoluteHeight(80 * proporcion); logo.SetAbsolutePosition(40f, 695f); doc.Add(logo); } catch (DocumentException dex) { //log exception here } //FIN DE ADICIÓN DE LOGO } doc.Add(tbl); writer.Close(); doc.Close(); ms.Seek(0, SeekOrigin.Begin); return(File(ms, "application/pdf")); }
private void btnImprimir_Click(object sender, EventArgs e) { try { BmsSoftware.ConfigSistema1.Default.TituloRelatorio = txtTitulo.Text; BmsSoftware.ConfigSistema1.Default.Save(); SalveConfig(NometelaSelec, NomeGridSelec); int i = 0; int TotalColuna = 0; foreach (DataGridViewColumn col in DataGridExport.Columns) { if (ctlColumnsToPrintCHKLBX.GetItemCheckState(i) == CheckState.Checked) { col.Visible = true; TotalColuna++; } else { col.Visible = false; } i++; } //Creating iTextSharp Table from the DataTable data PdfPTable pdfTable = new PdfPTable(TotalColuna); pdfTable.WidthPercentage = 90; //pdfTable.HorizontalAlignment = Element.ALIGN_LEFT; pdfTable.DefaultCell.BorderWidth = 1; float[] widths = new float[TotalColuna]; //Adding Header row int x = 0; foreach (DataGridViewColumn column in DataGridExport.Columns) { if (column.Visible) { var FontColour = new BaseColor(35, 31, 32); var Calibri8 = FontFactory.GetFont("HELVETICA", 16, FontColour); PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText, Calibri8)); //pdfTable.WidthPercentage = 100; // pdfTable.HorizontalAlignment = Element.ALIGN_LEFT; //pdfTable.HeaderHeight = column.Width; cell.HorizontalAlignment = 1; //0=Left, 1=Center, 2=Right widths[x] = column.Width; x++; pdfTable.SpacingAfter = 10; cell.BackgroundColor = new iTextSharp.text.BaseColor(240, 240, 240); pdfTable.AddCell(cell); } } pdfTable.SetWidths(widths); //Adding DataRow foreach (DataGridViewRow row in DataGridExport.Rows) { foreach (DataGridViewCell cell in row.Cells) { if (cell.Visible && row.Visible) { if (cell.Value != null) { var FontColour = new BaseColor(35, 31, 32); var Calibri8 = FontFactory.GetFont("HELVETICA", 16, FontColour); PdfPCell cell_Pdf = new PdfPCell(new Phrase(cell.EditedFormattedValue.ToString(), Calibri8)); String CelulaGrid = string.Empty; if (cell.EditedFormattedValue.ToString().IndexOf(",") != -1 && ValidacoesLibrary.ValidaTipoDecimal(cell.EditedFormattedValue.ToString())) { CelulaGrid = Convert.ToDecimal(cell.EditedFormattedValue.ToString()).ToString("n2"); PdfPCell cell_Pdf_TipoMoeda = new PdfPCell(new Phrase(CelulaGrid, Calibri8)); cell_Pdf_TipoMoeda.HorizontalAlignment = 2; //0=Left, 1=Center, 2=Right pdfTable.AddCell(cell_Pdf_TipoMoeda); } //else if (ValidacoesLibrary.ValidaTipoInt32(cell.EditedFormattedValue.ToString())) //{ // CelulaGrid = Convert.ToDecimal(cell.EditedFormattedValue.ToString()).ToString(); // PdfPCell cell_Pdf_Int = new PdfPCell(new Phrase(CelulaGrid)); // cell_Pdf_Int.HorizontalAlignment = 2; //0=Left, 1=Center, 2=Right // pdfTable.AddCell(cell_Pdf_Int); //} else if (cell.EditedFormattedValue.ToString().Length == 10 && ValidacoesLibrary.ValidaTipoDateTime(cell.EditedFormattedValue.ToString())) { CelulaGrid = Convert.ToDateTime(cell.EditedFormattedValue.ToString()).ToString("dd/MM/yyyy"); PdfPCell cell_Pdf_Date = new PdfPCell(new Phrase(CelulaGrid, Calibri8)); cell_Pdf_Date.HorizontalAlignment = 2; //0=Left, 1=Center, 2=Right pdfTable.AddCell(cell_Pdf_Date); } else { cell_Pdf.HorizontalAlignment = 0; //0=Left, 1=Center, 2=Right pdfTable.AddCell(cell_Pdf); } } else { pdfTable.AddCell(""); } } } } if (txtNomeArquivo.Text.Trim() == string.Empty) { txtNomeArquivo.Text = "ListadaPesquisa"; } //Exporting to PDF // string folderPath = "C:\\PDFs\\"; string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } using (FileStream stream = new FileStream(folderPath + @"\" + txtNomeArquivo.Text + ".pdf", FileMode.Create)) { //cb.SetFontAndSize(FontFactory.GetFont(FontFactory.HELVETICA).BaseFont, 14); Document pdfDoc = new Document(PageSize.A2, 20f, 10f, 80f, 10f); pdfDoc.AddTitle(txtTitulo.Text); PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream); PageEventHelper pageEventHelper = new PageEventHelper(); writer.PageEvent = pageEventHelper; pdfDoc.Open(); pdfDoc.Add(pdfTable); pdfDoc.Close(); stream.Close(); } foreach (DataGridViewColumn col in DataGridExport.Columns) { col.Visible = true; } MessageBox.Show("Arquivo " + txtNomeArquivo.Text + ".pdf gerado com sucesso!"); System.Diagnostics.Process Processo1 = null; if (File.Exists(folderPath + @"\" + txtNomeArquivo.Text + ".pdf")) { Processo1 = System.Diagnostics.Process.Start(folderPath + @"\" + txtNomeArquivo.Text + ".pdf"); } } catch (Exception ex) { MessageBox.Show("Erro ao exportar o arquivo PDF!"); MessageBox.Show("Erro técnico: " + ex.Message); } }
public async Task <MemoryStream> GenerarPDF(int id, string descripcionEmpresa) { BE_TxSIMConsolidado p = context.ExecuteSqlViewId <BE_TxSIMConsolidado>(SP_GET_POR_ID, new BE_TxSIMConsolidado { IdSIMConsolidado = id }); var listaDocumentoSIM = context.ExecuteSqlViewFindByCondition <BE_TxSIM>(SP_GET_CONSOLIDADO_SIM, new BE_TxSIMConsolidado { IdSIMConsolidado = id }).ToList(); var listaIndiceBursal = context.ExecuteSqlViewFindByCondition <BE_TxSIMIndiceBursal>(SP_GET_CONSOLIDADO_INDICE_BURSAL, new BE_TxSIMConsolidado { IdSIMConsolidado = id }).ToList(); var listaLesionBursa = context.ExecuteSqlViewFindByCondition <BE_TxSIMLesionBursa>(SP_GET_CONSOLIDADO_LESION_BURSAL, new BE_TxSIMConsolidado { IdSIMConsolidado = id }).ToList(); var listaLesionTimo = context.ExecuteSqlViewFindByCondition <BE_TxSIMLesionTimo>(SP_GET_CONSOLIDADO_LESION_TIMO, new BE_TxSIMConsolidado { IdSIMConsolidado = id }).ToList(); var listaLesiones = context.ExecuteSqlViewFindByCondition <BE_TxSIMLesiones>(SP_GET_CONSOLIDADO_LESIONES, new BE_TxSIMConsolidado { IdSIMConsolidado = id }).ToList(); var listaFotos = context.ExecuteSqlViewFindByCondition <BE_TxSIMFotos>(SP_GET_CONSOLIDADO_FOTOS, new BE_TxSIMConsolidado { IdSIMConsolidado = id }).ToList(); return(await Task.Run(() => { Document doc = new Document(); doc.SetPageSize(PageSize.Letter); // points to cm doc.SetMargins(28.34f, 28.34f, 85f, 85f); MemoryStream ms = new MemoryStream(); PdfWriter write = PdfWriter.GetInstance(doc, ms); doc.AddAuthor("Grupo SBA"); doc.AddTitle("Invetsa"); var pe = new PageEventHelper(); pe.FlagCerrado = true; pe.FlagModulo = "SIM"; write.PageEvent = pe; // Colocamos la fuente que deseamos que tenga el documento BaseFont helvetica = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, true); // Titulo iTextSharp.text.Font titulo = new iTextSharp.text.Font(helvetica, 16f, iTextSharp.text.Font.BOLD, new BaseColor(103, 93, 152)); iTextSharp.text.Font tituloBlanco = new iTextSharp.text.Font(helvetica, 18f, iTextSharp.text.Font.NORMAL, BaseColor.White); iTextSharp.text.Font subTitulo = new iTextSharp.text.Font(helvetica, 10f, iTextSharp.text.Font.BOLD, new BaseColor(103, 93, 152)); iTextSharp.text.Font subTituloParticiones = new iTextSharp.text.Font(helvetica, 10f, iTextSharp.text.Font.BOLD, new BaseColor(103, 93, 152)); iTextSharp.text.Font parrafoBlanco = new iTextSharp.text.Font(helvetica, 10f, iTextSharp.text.Font.BOLD, BaseColor.White); iTextSharp.text.Font parrafoNegrita = new iTextSharp.text.Font(helvetica, 10f, iTextSharp.text.Font.BOLD, BaseColor.Black); iTextSharp.text.Font parrafoNegro = new iTextSharp.text.Font(helvetica, 10f, iTextSharp.text.Font.NORMAL, BaseColor.Black); iTextSharp.text.Font parrafoRojo = new iTextSharp.text.Font(helvetica, 10f, iTextSharp.text.Font.NORMAL, BaseColor.Red); pe.HeaderLeft = " "; pe.HeaderFont = parrafoBlanco; pe.HeaderRight = " "; doc.Open(); var tbl = new PdfPTable(new float[] { 100f }) { WidthPercentage = 100 }; var title = string.Format("INFORME DEL SISTEMA INTEGRADO DE MONITOREO DE CAMPO - {0}", id, titulo); var c1 = new PdfPCell(new Phrase(title, titulo)) { Border = 0 }; c1.HorizontalAlignment = Element.ALIGN_CENTER; c1.VerticalAlignment = Element.ALIGN_MIDDLE; tbl.AddCell(c1); c1 = new PdfPCell(new Phrase(p.DescripcionEmpresa, titulo)) { Border = 0 }; c1.HorizontalAlignment = Element.ALIGN_CENTER; c1.VerticalAlignment = Element.ALIGN_MIDDLE; tbl.AddCell(c1); c1.Phrase = new Phrase("", parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase("", parrafoNegro); tbl.AddCell(c1); doc.Add(tbl); tbl = new PdfPTable(new float[] { 7f, 20f, 30f, 29f, 7f, 7f }) { WidthPercentage = 100f }; c1 = new PdfPCell(); c1.Phrase = new Phrase("LISTA DE SISTEMA INTEGRADO DE MONITOREO DE CAMPO", subTitulo); c1.Border = 0; c1.Colspan = 6; tbl.AddCell(c1); c1 = new PdfPCell(); c1.Phrase = new Phrase("", parrafoNegro); c1.Border = 0; c1.Colspan = 6; tbl.AddCell(c1); c1 = new PdfPCell(); c1 = new PdfPCell(new Phrase("Edad", parrafoBlanco)) { BackgroundColor = new BaseColor(51, 153, 68), HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE }; tbl.AddCell(c1); c1.Phrase = new Phrase("Fecha/Hora", parrafoBlanco); tbl.AddCell(c1); c1.Phrase = new Phrase("Granja", parrafoBlanco); tbl.AddCell(c1); c1.Phrase = new Phrase("Zona", parrafoBlanco); tbl.AddCell(c1); c1.Phrase = new Phrase("Galpón", parrafoBlanco); tbl.AddCell(c1); c1.Phrase = new Phrase("Nro Pollos", parrafoBlanco); tbl.AddCell(c1); foreach (BE_TxSIM item in listaDocumentoSIM) { c1 = new PdfPCell(); c1.Phrase = new Phrase(item.Edad.ToString(), parrafoNegro); c1.HorizontalAlignment = Element.ALIGN_CENTER; tbl.AddCell(c1); c1.Phrase = new Phrase(item.FecHoraRegistro.ToString(), parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase(item.CodigoPlanta, parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase(item.Zona, parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase(item.Galpon.ToString(), parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase(item.NroPollos.ToString(), parrafoNegro); tbl.AddCell(c1); } c1 = new PdfPCell(); c1.Phrase = new Phrase("", parrafoNegro); c1.Border = 0; c1.Colspan = 6; tbl.AddCell(c1); doc.Add(tbl); tbl = new PdfPTable(new float[] { 7f, 10f, 10f, 10f, 10f, 10f, 10f, 10f, 10f, 13f }) { WidthPercentage = 100f }; c1 = new PdfPCell(); c1.Phrase = new Phrase("I.ÍNDICE DE ÓRGANOS LINFOIDES", subTitulo); c1.Border = 0; c1.Colspan = 10; tbl.AddCell(c1); c1 = new PdfPCell(); c1.Phrase = new Phrase("", parrafoNegro); c1.Border = 0; c1.Colspan = 10; tbl.AddCell(c1); c1 = new PdfPCell(); c1 = new PdfPCell(new Phrase("Edad", parrafoBlanco)) { BackgroundColor = new BaseColor(51, 153, 68), HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE }; tbl.AddCell(c1); c1.Phrase = new Phrase("Peso Corporal (g)", parrafoBlanco); tbl.AddCell(c1); c1.Phrase = new Phrase("Peso de Bursa (g)", parrafoBlanco); tbl.AddCell(c1); c1.Phrase = new Phrase("Peso de Bazo (g)", parrafoBlanco); tbl.AddCell(c1); c1.Phrase = new Phrase("Peso de Timo (g)", parrafoBlanco); tbl.AddCell(c1); c1.Phrase = new Phrase("Peso de Hígado (g)", parrafoBlanco); tbl.AddCell(c1); c1.Phrase = new Phrase("Índice Bursal", parrafoBlanco); tbl.AddCell(c1); c1.Phrase = new Phrase("Índice Timico", parrafoBlanco); tbl.AddCell(c1); c1.Phrase = new Phrase("Índice Hepático", parrafoBlanco); tbl.AddCell(c1); c1.Phrase = new Phrase("Bursómetro", parrafoBlanco); tbl.AddCell(c1); foreach (BE_TxSIMIndiceBursal item in listaIndiceBursal) { c1 = new PdfPCell(); c1.Phrase = new Phrase(item.Edad.ToString(), parrafoNegro); c1.HorizontalAlignment = Element.ALIGN_CENTER; tbl.AddCell(c1); c1.Phrase = new Phrase(((int)item.PesoCorporal).ToString(), parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase(item.PesoBursa.ToString(), parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase(item.PesoBazo.ToString(), parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase(item.PesoTimo.ToString(), parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase(item.PesoHigado.ToString(), parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase(item.IndiceBursal.ToString(), parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase(item.IndiceTimico.ToString(), parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase(item.IndiceHepatico.ToString(), parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase(item.Bursometro.ToString(), parrafoNegro); tbl.AddCell(c1); } c1 = new PdfPCell(); c1.Phrase = new Phrase("", parrafoNegro); c1.Border = 0; c1.Colspan = 10; tbl.AddCell(c1); doc.Add(tbl); tbl = new PdfPTable(new float[] { 10f, 15f, 15f, 15f, 15f, 15f, 15f }) { WidthPercentage = 100f }; c1 = new PdfPCell(); c1.Phrase = new Phrase("II. SCORE DE LESIONES HISTOPATOLÓGICAS DE BURSA Y TIMO", subTitulo); c1.Border = 0; c1.Colspan = 7; tbl.AddCell(c1); c1 = new PdfPCell(); c1.Phrase = new Phrase("", parrafoNegro); c1.Border = 0; c1.Colspan = 7; tbl.AddCell(c1); c1 = new PdfPCell(); c1 = new PdfPCell(new Phrase("EDAD", parrafoBlanco)) { BackgroundColor = new BaseColor(51, 153, 68), HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE }; tbl.AddCell(c1); c1.Phrase = new Phrase("SCORE DE LESIÓN DE BURSA", parrafoBlanco); c1.Colspan = 5; tbl.AddCell(c1); c1.Phrase = new Phrase("PROMEDIO", parrafoBlanco); tbl.AddCell(c1); int v_Edad = 0; foreach (BE_TxSIMLesionBursa item in listaLesionBursa) { c1 = new PdfPCell(); if (v_Edad != item.Edad) { c1.Phrase = new Phrase(item.Edad.ToString(), parrafoNegro); c1.HorizontalAlignment = Element.ALIGN_CENTER; tbl.AddCell(c1); } c1.Phrase = new Phrase(item.Valor.ToString(), parrafoNegro); c1.HorizontalAlignment = Element.ALIGN_CENTER; tbl.AddCell(c1); v_Edad = item.Edad; } c1 = new PdfPCell(); c1.Phrase = new Phrase("", parrafoNegro); c1.Border = 0; c1.Colspan = 7; tbl.AddCell(c1); c1 = new PdfPCell(); c1 = new PdfPCell(new Phrase("EDAD", parrafoBlanco)) { BackgroundColor = new BaseColor(51, 153, 68), HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE }; tbl.AddCell(c1); c1.Phrase = new Phrase("SCORE DE LESIÓN DE TIMO", parrafoBlanco); c1.Colspan = 5; tbl.AddCell(c1); c1.Phrase = new Phrase("PROMEDIO", parrafoBlanco); tbl.AddCell(c1); v_Edad = 0; foreach (BE_TxSIMLesionTimo item in listaLesionTimo) { c1 = new PdfPCell(); if (v_Edad != item.Edad) { c1.Phrase = new Phrase(item.Edad.ToString(), parrafoNegro); c1.HorizontalAlignment = Element.ALIGN_CENTER; tbl.AddCell(c1); } c1.Phrase = new Phrase(item.Valor.ToString(), parrafoNegro); c1.HorizontalAlignment = Element.ALIGN_CENTER; tbl.AddCell(c1); v_Edad = item.Edad; } c1 = new PdfPCell(); c1.Phrase = new Phrase("", parrafoNegro); c1.Border = 0; c1.Colspan = 7; tbl.AddCell(c1); doc.Add(tbl); tbl = new PdfPTable(new float[] { 10f, 30f, 30f, 30f }) { WidthPercentage = 100f }; c1 = new PdfPCell(); c1.Phrase = new Phrase("III. HALLAZGO DE LESIONES HISTOPATOLÓGICAS DE ÓRGANOS", subTitulo); c1.Border = 0; c1.Colspan = 4; tbl.AddCell(c1); c1 = new PdfPCell(); c1.Phrase = new Phrase("", parrafoNegro); c1.Border = 0; c1.Colspan = 4; tbl.AddCell(c1); c1 = new PdfPCell(); c1 = new PdfPCell(new Phrase("EDAD", parrafoBlanco)) { BackgroundColor = new BaseColor(51, 153, 68), HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE }; tbl.AddCell(c1); c1.Phrase = new Phrase("LESIONES DE DUODENO", parrafoBlanco); tbl.AddCell(c1); c1.Phrase = new Phrase("LESIONES EN INSTESTINO MEDIO", parrafoBlanco); tbl.AddCell(c1); c1.Phrase = new Phrase("LESIONES EN HÍGADO", parrafoBlanco); tbl.AddCell(c1); foreach (BE_TxSIMLesiones item in listaLesiones) { c1 = new PdfPCell(); c1.Phrase = new Phrase(item.Edad.ToString(), parrafoNegro); c1.HorizontalAlignment = Element.ALIGN_CENTER; tbl.AddCell(c1); c1.Phrase = new Phrase(item.LesionesDeudemo, parrafoNegro); c1.HorizontalAlignment = Element.ALIGN_LEFT; tbl.AddCell(c1); c1.Phrase = new Phrase(item.LesionesIntestinoMedio, parrafoNegro); c1.HorizontalAlignment = Element.ALIGN_LEFT; tbl.AddCell(c1); c1.Phrase = new Phrase(item.LesionesHigado, parrafoNegro); c1.HorizontalAlignment = Element.ALIGN_LEFT; tbl.AddCell(c1); } c1 = new PdfPCell(); c1.Phrase = new Phrase("", parrafoNegro); c1.Border = 0; c1.Colspan = 4; tbl.AddCell(c1); doc.Add(tbl); tbl = new PdfPTable(new float[] { 100f }) { WidthPercentage = 100f }; c1 = new PdfPCell(); c1.Phrase = new Phrase("IV. COMENTARIO", subTitulo); c1.Border = 0; c1.VerticalAlignment = Element.ALIGN_MIDDLE; tbl.AddCell(c1); c1.Phrase = new Phrase(p.Observacion, parrafoNegro); tbl.AddCell(c1); c1 = new PdfPCell(); c1.Phrase = new Phrase("", parrafoNegro); c1.Border = 0; tbl.AddCell(c1); doc.Add(tbl); tbl = new PdfPTable(new float[] { 50f, 50f }) { WidthPercentage = 100f }; c1 = new PdfPCell(); c1.Phrase = new Phrase("V. FOTOS", subTitulo); c1.Border = 0; c1.Colspan = 2; tbl.AddCell(c1); c1 = new PdfPCell(); c1.Phrase = new Phrase("", parrafoNegro); c1.Border = 0; c1.Colspan = 2; tbl.AddCell(c1); var countFotos = listaFotos.Count(); iTextSharp.text.Image foto = null; foreach (BE_TxSIMFotos item in listaFotos) { foto = ImagenBase64ToImagen(item.Foto, 270f, 200f); if (foto != null) { c1 = new PdfPCell(foto); c1.HorizontalAlignment = Element.ALIGN_CENTER; c1.VerticalAlignment = Element.ALIGN_MIDDLE; c1.Border = 0; tbl.AddCell(c1); } } if ((countFotos % 2) != 0) { c1 = new PdfPCell(new Phrase(" ")); c1.Border = 0; tbl.AddCell(c1); } c1 = new PdfPCell(); c1.Phrase = new Phrase("", parrafoNegro); c1.Border = 0; c1.Colspan = 2; tbl.AddCell(c1); doc.Add(tbl); write.Close(); doc.Close(); ms.Seek(0, SeekOrigin.Begin); var file = ms; return file; })); }
private async Task <byte[]> CreateAlsrPdf(int id) { var reportModel = await db.BillsAlsrReports .Where(r => r.ID == id) .Include(r => r.AlsrBillReviewSnapshots.Select(s => s.Bill)) .Include(r => r.AlsrBillReviewSnapshots.Select(s => s.BillVersion)) .Include(r => r.AlsrBillReviewSnapshots.Select(s => s.CreatedByUser)) .Include(r => r.AlsrBillReviewSnapshots.Select(s => s.CreatedByUserInDept)) .Include(r => r.AlsrBillReviewSnapshots.Select(s => s.CreatedByUserInDiv)) .Include(r => r.AlsrBillReviewSnapshots.Select(s => s.Recommendation)) .FirstOrDefaultAsync(); // initialize iText document using (MemoryStream ms = new MemoryStream()) { string agencyTitle = reportModel.AlsrBillReviewSnapshots.FirstOrDefault().CreatedByUserInDept.Description; //initialize PDF Document var doc = new Document(PageSize.LETTER, 36, 36, 36, 36); PdfWriter writer = PdfWriter.GetInstance(doc, ms); // add page # footer PageEventHelper pageEventHelper = new PageEventHelper(); writer.PageEvent = pageEventHelper; doc.AddAuthor(agencyTitle); doc.AddCreationDate(); doc.Open(); // formatting variables float tableFullPageWidth = 540f; float tableCellBottomPadding = 6f; float paragraphSpacingBefore = 18f; // header (used on each page) Chunk alsrAgencyHeader = new Chunk(agencyTitle); Chunk alsrHeaderLine2 = new Chunk("\nAgency Legislative Status Report"); Chunk alsrHeaderLine3 = new Chunk("\n78th Legislative Session (2015)"); Paragraph header = new Paragraph(); header.Alignment = Element.ALIGN_CENTER; header.Add(alsrAgencyHeader); header.Add(alsrHeaderLine2); header.Add(alsrHeaderLine3); // cover sheet Chapter coverSheet = new Chapter(header, 1); coverSheet.NumberDepth = 0; coverSheet.BookmarkTitle = "Cover Sheet"; doc.Add(coverSheet); // individual BillReviews for (int i = 0; i < reportModel.AlsrBillReviewSnapshots.Count; i++) { Chapter reviewPage = new Chapter(header, 1); reviewPage.NumberDepth = 0; reviewPage.BookmarkTitle = reportModel.AlsrBillReviewSnapshots[i].Bill.CompositeBillNumber; // Agency contact section PdfPTable contactTable = new PdfPTable(2); contactTable.DefaultCell.Border = Rectangle.NO_BORDER; contactTable.DefaultCell.PaddingBottom = tableCellBottomPadding; contactTable.TotalWidth = tableFullPageWidth; contactTable.LockedWidth = true; contactTable.SpacingBefore = paragraphSpacingBefore; contactTable.AddCell(string.Format("Agency: {0}", agencyTitle)); contactTable.AddCell(string.Format("Delivery Date: {0}", reportModel.GovOfficeDeliveryDate.ToShortDateString())); PdfPCell contactNameCell = new PdfPCell(new Phrase(string.Format("Contact Name: Ann Wilkinson (Deputy Administrator)"))); contactNameCell.Colspan = 2; contactNameCell.Border = Rectangle.NO_BORDER; contactNameCell.PaddingBottom = tableCellBottomPadding; contactTable.AddCell(contactNameCell); contactTable.AddCell(string.Format("Phone: 775-684-0222")); contactTable.AddCell(string.Format("Fax: 775-684-0260")); reviewPage.Add(contactTable); // Bill info section PdfPTable billInfoTable = new PdfPTable(3); billInfoTable.DefaultCell.Border = Rectangle.NO_BORDER; billInfoTable.DefaultCell.PaddingBottom = tableCellBottomPadding; billInfoTable.TotalWidth = tableFullPageWidth; billInfoTable.LockedWidth = true; billInfoTable.SpacingBefore = paragraphSpacingBefore; float[] billInfoTableWidths = new float[] { 1, 1, 2 }; billInfoTable.SetWidths(billInfoTableWidths); billInfoTable.AddCell(string.Format("Bill No: {0}", reportModel.AlsrBillReviewSnapshots[i].Bill.CompositeBillNumber)); billInfoTable.AddCell(string.Format("BDR No: {0}", reportModel.AlsrBillReviewSnapshots[i].Bill.CompositeNelisBdrNumber)); billInfoTable.AddCell(string.Format("Sponsor: {0}", reportModel.AlsrBillReviewSnapshots[i].BillVersion.Sponsor)); PdfPCell reprintNoCell = new PdfPCell(new Phrase(string.Format("Reprint No: {0}", reportModel.AlsrBillReviewSnapshots[i].BillVersion.VersionDescription))); reprintNoCell.Colspan = 4; reprintNoCell.Border = Rectangle.NO_BORDER; reprintNoCell.PaddingBottom = tableCellBottomPadding; billInfoTable.AddCell(reprintNoCell); reviewPage.Add(billInfoTable); // BillReview section Paragraph billReviewHeaderParagraph = new Paragraph(string.Format("This Bill Review is being provided on behalf of Agency: {1}", agencyTitle, reportModel.AlsrBillReviewSnapshots[i].CreatedByUserInDiv.Description)); billReviewHeaderParagraph.SpacingBefore = paragraphSpacingBefore; reviewPage.Add(billReviewHeaderParagraph); PdfPTable billReviewTable = new PdfPTable(2); billReviewTable.DefaultCell.Border = Rectangle.NO_BORDER; billReviewTable.DefaultCell.PaddingBottom = tableCellBottomPadding; billReviewTable.DefaultCell.PaddingRight = tableCellBottomPadding; billReviewTable.TotalWidth = tableFullPageWidth; billReviewTable.LockedWidth = true; billReviewTable.SpacingBefore = paragraphSpacingBefore; float[] billReviewTableWidths = new float[] { 1, 2 }; billReviewTable.SetWidths(billReviewTableWidths); billReviewTable.AddCell("Position:"); billReviewTable.AddCell(reportModel.AlsrBillReviewSnapshots[i].Recommendation.Description); billReviewTable.AddCell("Agency is tracking this Bill:"); billReviewTable.AddCell((reportModel.AlsrBillReviewSnapshots[i].ActivelyTracking ? "Yes" : "No")); billReviewTable.AddCell("Information/testimony or data to be provided by agency:"); billReviewTable.AddCell((reportModel.AlsrBillReviewSnapshots[i].InformationToBeProvided ? "Yes" : "No")); billReviewTable.AddCell("Policy impact on agency:"); string policyImpact = ""; switch (reportModel.AlsrBillReviewSnapshots[i].PolicyImpact) { case null: policyImpact = "Unknown"; break; case false: policyImpact = "No"; break; case true: policyImpact = "Yes"; break; default: break; } billReviewTable.AddCell(policyImpact); billReviewTable.AddCell("Fiscal impact on agency:"); billReviewTable.AddCell((reportModel.AlsrBillReviewSnapshots[i].FiscalNoteSubmitted ? "Yes" : "No")); billReviewTable.AddCell("Estimated fiscal impact for biennium:"); billReviewTable.AddCell(string.Format("${0}", reportModel.AlsrBillReviewSnapshots[i].FiscalImpactBiennium)); reviewPage.Add(billReviewTable); Paragraph billReviewCommentsHeaderParagraph = new Paragraph("Comments: Would passage of this bill constitute good public policy?\n"); billReviewCommentsHeaderParagraph.SpacingBefore = paragraphSpacingBefore; reviewPage.Add(billReviewCommentsHeaderParagraph); Paragraph billReviewCommentsParagraph = new Paragraph(reportModel.AlsrBillReviewSnapshots[i].Comments); //billReviewCommentsParagraph.SpacingBefore = paragraphSpacingBefore; reviewPage.Add(billReviewCommentsParagraph); doc.Add(reviewPage); } doc.Close(); writer.Close(); return(ms.ToArray()); } }
public async Task <IActionResult> activosDescargadosJefePdf(int idJefe) { Document doc = new Document(PageSize.Letter); doc.SetMargins(40f, 40f, 40f, 40f); MemoryStream ms = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(doc, ms); //Instanciamos la clase para el paginado y la fecha de impresión var pe = new PageEventHelper(); writer.PageEvent = pe; doc.AddAuthor("Asgard"); doc.AddTitle("Reporte de historial de descargos de activos asignados"); doc.Open(); //Inicia cuerpo del reporte //Estilo y fuente personalizada BaseFont fuente = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1250, true); iTextSharp.text.Font parrafo = new iTextSharp.text.Font(fuente, 12f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); BaseFont fuente2 = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, true); iTextSharp.text.Font parrafo2 = new iTextSharp.text.Font(fuente2, 10f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); BaseFont fuente3 = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, true); iTextSharp.text.Font parrafo3 = new iTextSharp.text.Font(fuente3, 15f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); BaseFont fuente4 = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1250, true); iTextSharp.text.Font parrafo4 = new iTextSharp.text.Font(fuente4, 11f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); //Para las celdas BaseFont fuente5 = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, true); iTextSharp.text.Font parrafo5 = new iTextSharp.text.Font(fuente5, 10f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0, 0)); //Encabezado using (BDAcaassAFContext bd = new BDAcaassAFContext()) { CooperativaAF oCooperativaAF = new CooperativaAF(); Cooperativa oCooperativa = bd.Cooperativa.Where(p => p.Dhabilitado == 1).First(); oCooperativaAF.idcooperativa = oCooperativa.IdCooperativa; oCooperativaAF.nombre = oCooperativa.Nombre; oCooperativaAF.descripcion = oCooperativa.Descripcion; //Se agrega el encabezado var tbl1 = new PdfPTable(new float[] { 11f, 89f }) { WidthPercentage = 100f }; tbl1.AddCell(new PdfPCell(new Phrase(" ", parrafo2)) { Border = 0, Rowspan = 2 }); tbl1.AddCell(new PdfPCell(new Phrase(oCooperativa.Descripcion.ToUpper(), parrafo2)) { Border = 0, HorizontalAlignment = 1 }); tbl1.AddCell(new PdfPCell(new Phrase(oCooperativa.Nombre.ToUpper(), parrafo3)) { Border = 0, HorizontalAlignment = 1 }); doc.Add(tbl1); doc.Add(new Phrase("\n")); } doc.Add(new Phrase("\n")); //Línea separadora Chunk linea = new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(1f, 100f, BaseColor.Black, Element.ALIGN_CENTER, 1f)); doc.Add(linea); doc.Add(new Paragraph("REPORTE DE HISTORIAL DE DESCARGOS DE ACTIVOS ASIGNADOS", parrafo) { Alignment = Element.ALIGN_CENTER }); //Espacio en blanco doc.Add(Chunk.Newline); //Agregamos una tabla var tbl = new PdfPTable(new float[] { 30f, 35f, 40f, 40f, 30f }) { WidthPercentage = 100f }; var c1 = new PdfPCell(new Phrase("CORRELATIVO", parrafo2)); var c2 = new PdfPCell(new Phrase("FECHA INGRESO", parrafo2)); var c3 = new PdfPCell(new Phrase("DESCRIPCIÓN", parrafo2)); var c4 = new PdfPCell(new Phrase("ÁREA DE NEGOCIOS", parrafo2)); var c5 = new PdfPCell(new Phrase("RESPONSABLE", parrafo2)); //Agregamos a la tabla las celdas tbl.AddCell(c1); tbl.AddCell(c2); tbl.AddCell(c3); tbl.AddCell(c4); tbl.AddCell(c5); //Extraemos de la base y llenamos las celdas using (BDAcaassAFContext bd = new BDAcaassAFContext()) { Empleado oempleado = bd.Empleado.Where(p => p.IdEmpleado == idJefe).FirstOrDefault(); AreaDeNegocio oarea = bd.AreaDeNegocio.Where(p => p.IdAreaNegocio == oempleado.IdAreaDeNegocio).FirstOrDefault(); List <BajaAF> lista = (from activo in bd.ActivoFijo join noFormulario in bd.FormularioIngreso on activo.NoFormulario equals noFormulario.NoFormulario join resposable in bd.Empleado on activo.IdResponsable equals resposable.IdEmpleado join area in bd.AreaDeNegocio on resposable.IdAreaDeNegocio equals area.IdAreaNegocio join cargo in bd.Cargos on resposable.IdCargo equals cargo.IdCargo where activo.EstadoActual == 0 && activo.EstaAsignado == 1 && area.IdAreaNegocio == oarea.IdAreaNegocio orderby activo.CorrelativoBien select new BajaAF { IdBien = activo.IdBien, Codigo = activo.CorrelativoBien, fechacadena = noFormulario.FechaIngreso == null ? " " : ((DateTime)noFormulario.FechaIngreso).ToString("dd-MM-yyyy"), Desripcion = activo.Desripcion, AreaDeNegocio = area.Nombre, Resposnsable = resposable.Nombres + " " + resposable.Apellidos, //cargo = cargo.Cargo, }).ToList(); foreach (var activosbaja in lista) { c1.Phrase = new Phrase(activosbaja.Codigo, parrafo5); c2.Phrase = new Phrase(activosbaja.fechacadena, parrafo5); c3.Phrase = new Phrase(activosbaja.Desripcion, parrafo5); c4.Phrase = new Phrase(activosbaja.AreaDeNegocio, parrafo5); c5.Phrase = new Phrase(activosbaja.Resposnsable, parrafo5); //Agregamos a la tabla tbl.AddCell(c1); tbl.AddCell(c2); tbl.AddCell(c3); tbl.AddCell(c4); tbl.AddCell(c5); } //INICIO DE ADICIÓN DE LOGO CooperativaAF oCooperativaAF = new CooperativaAF(); Cooperativa oCooperativa = bd.Cooperativa.Where(p => p.Dhabilitado == 1).First(); oCooperativaAF.idcooperativa = oCooperativa.IdCooperativa; try { iTextSharp.text.Image logo = null; logo = iTextSharp.text.Image.GetInstance(oCooperativa.Logo.ToString()); logo.Alignment = iTextSharp.text.Image.ALIGN_LEFT; logo.Border = iTextSharp.text.Rectangle.NO_BORDER; logo.BorderColor = iTextSharp.text.BaseColor.White; logo.ScaleToFit(170f, 100f); float ancho = logo.Width; float alto = logo.Height; float proporcion = alto / ancho; logo.ScaleAbsoluteWidth(80); logo.ScaleAbsoluteHeight(80 * proporcion); logo.SetAbsolutePosition(40f, 695f); doc.Add(logo); } catch (DocumentException dex) { //log exception here } //FIN DE ADICIÓN DE LOGO } doc.Add(tbl); writer.Close(); doc.Close(); ms.Seek(0, SeekOrigin.Begin); return(File(ms, "application/pdf")); }
public async Task <MemoryStream> GenerarPDF(BE_TxExamenFisicoPollito entidad) { BE_TxExamenFisicoPollito item = GetByIdPDF(entidad); CalidadRepository ICalidad = new CalidadRepository(context); IEnumerable <BE_Calidad> calidad = ICalidad.GetAllCalidad(new BE_Calidad { Descripcion = "" }); return(await Task.Run(() => { Document doc = new Document(); doc.SetPageSize(PageSize.Letter); // points to cm doc.SetMargins(28.34f, 28.34f, 85f, 85f); MemoryStream ms = new MemoryStream(); PdfWriter write = PdfWriter.GetInstance(doc, ms); doc.AddAuthor("Grupo SBA"); doc.AddTitle("Invetsa"); var pe = new PageEventHelper(); pe.FlagCerrado = Boolean.Parse(item.FlgCerrado.ToString()); write.PageEvent = pe; // Colocamos la fuente que deseamos que tenga el documento BaseFont helvetica = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, true); // Titulo iTextSharp.text.Font titulo = new iTextSharp.text.Font(helvetica, 20f, iTextSharp.text.Font.BOLD, new BaseColor(103, 93, 152)); iTextSharp.text.Font tituloBlanco = new iTextSharp.text.Font(helvetica, 18f, iTextSharp.text.Font.NORMAL, BaseColor.White); iTextSharp.text.Font subTitulo = new iTextSharp.text.Font(helvetica, 14f, iTextSharp.text.Font.BOLD, new BaseColor(103, 93, 152)); iTextSharp.text.Font parrafoBlanco = new iTextSharp.text.Font(helvetica, 10f, iTextSharp.text.Font.BOLD, BaseColor.White); iTextSharp.text.Font parrafoNegro = new iTextSharp.text.Font(helvetica, 10f, iTextSharp.text.Font.NORMAL, BaseColor.Black); iTextSharp.text.Font parrafoRojo = new iTextSharp.text.Font(helvetica, 10f, iTextSharp.text.Font.NORMAL, BaseColor.Red); pe.HeaderLeft = " "; pe.HeaderFont = parrafoBlanco; pe.HeaderRight = " "; doc.Open(); var tblTitulo = new PdfPTable(new float[] { 100f }) { WidthPercentage = 100 }; var title = string.Format("EXÁMEN FÍSICO DE POLLITO BB - {0}", entidad.IdExamenFisico, titulo); var c1Titulo = new PdfPCell(new Phrase(title, titulo)) { Border = 0 }; c1Titulo.HorizontalAlignment = Element.ALIGN_CENTER; c1Titulo.VerticalAlignment = Element.ALIGN_MIDDLE; tblTitulo.AddCell(c1Titulo); doc.Add(tblTitulo); doc.Add(new Phrase(" ")); doc.Add(new Phrase(" ")); var tbl = new PdfPTable(new float[] { 12f, 37f, 4f, 20f, 27f }) { WidthPercentage = 100 }; var c1 = new PdfPCell(new Phrase("Compañia:", parrafoNegro)) { Border = 0, PaddingBottom = 5f }; var c2 = new PdfPCell(new Phrase(item.DescripcionEmpresa, parrafoNegro)) { Border = 0, PaddingBottom = 5f }; var c3 = new PdfPCell(new Phrase("", parrafoNegro)) { Border = 0, PaddingBottom = 5f }; var c4 = new PdfPCell(new Phrase("Unidad - Planta:", parrafoNegro)) { Border = 0, PaddingBottom = 5f }; var c5 = new PdfPCell(new Phrase(item.DescripcionPlanta.ToString(), parrafoNegro)) { Border = 0, PaddingBottom = 5f }; tbl.AddCell(c1); tbl.AddCell(c2); tbl.AddCell(c3); tbl.AddCell(c4); tbl.AddCell(c5); c1.Phrase = new Phrase("Fecha:", parrafoNegro); c2.Phrase = new Phrase(DateTime.Parse(item.FecRegistro.ToString()).ToShortDateString(), parrafoNegro); c3.Phrase = new Phrase("", parrafoNegro); c4.Phrase = new Phrase("Hora:", parrafoNegro); c5.Phrase = new Phrase(DateTime.Parse(item.FecHoraRegistro.ToString()).ToShortTimeString(), parrafoNegro); tbl.AddCell(c1); tbl.AddCell(c2); tbl.AddCell(c3); tbl.AddCell(c4); tbl.AddCell(c5); c1.Phrase = new Phrase("Responsable:", parrafoNegro); c2.Phrase = new Phrase(item.ResponsablePlanta, parrafoNegro); c3.Phrase = new Phrase("", parrafoNegro); c4.Phrase = new Phrase("Responsable Invetsa:", parrafoNegro); c5.Phrase = new Phrase(item.ResponsableInvetsa, parrafoNegro); tbl.AddCell(c1); tbl.AddCell(c2); tbl.AddCell(c3); tbl.AddCell(c4); tbl.AddCell(c5); c1.Phrase = new Phrase(" ", parrafoNegro); c1.Colspan = 5; tbl.AddCell(c1); doc.Add(tbl); tbl = new PdfPTable(new float[] { 100f }) { WidthPercentage = 100 }; c1.Phrase = new Phrase("EVALUACIÓN FÍSICA DE CALIDAD DE POLLO BB", tituloBlanco); c1.BackgroundColor = new BaseColor(103, 93, 152); c1.PaddingBottom = 8f; c1.VerticalAlignment = Element.ALIGN_MIDDLE; tbl.AddCell(c1); doc.Add(tbl); tbl = new PdfPTable(new float[] { 15f, 15f, 20f, 15f, 15f, 20f }) { WidthPercentage = 100f }; c1 = new PdfPCell(); c1.Phrase = new Phrase(" ", parrafoNegro); c1.Border = 0; c1.Colspan = 6; tbl.AddCell(c1); c1 = new PdfPCell(); c1.Phrase = new Phrase("Lote:", parrafoNegro); c1.Border = 0; c1.BackgroundColor = new BaseColor(211, 211, 211); tbl.AddCell(c1); c1.Phrase = new Phrase(item.Lote, parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase("Edad Reproductora", parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase(item.EdadReproductora, parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase("Nacedora N°:", parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase(int.Parse(item.NumeroNacedora.ToString()).ToString("N"), parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase("Línea Genética:", parrafoNegro); tbl.AddCell(c1); c1.Phrase = new Phrase(item.LineaGenetica, parrafoNegro); c1.Colspan = 5; tbl.AddCell(c1); //Insertamos una linea en blanco en la tabla c1 = new PdfPCell(); c1.Phrase = new Phrase(" ", parrafoNegro); c1.Border = 0; c1.Colspan = 6; tbl.AddCell(c1); doc.Add(tbl); tbl = new PdfPTable(new float[] { 20f, 15f, 75f }) { WidthPercentage = 100f }; c1 = new PdfPCell(); c1.Phrase = new Phrase("Pollitos muestra", parrafoNegro); c1.BackgroundColor = new BaseColor(211, 211, 211); c1.Padding = 6f; tbl.AddCell(c1); c2 = new PdfPCell(); c2.Phrase = new Phrase("100", parrafoNegro); c2.HorizontalAlignment = Element.ALIGN_CENTER; c2.Padding = 6f; tbl.AddCell(c2); c3 = new PdfPCell(); c3.Phrase = new Phrase(" ", parrafoNegro); c3.Border = 0; tbl.AddCell(c3); c1.Phrase = new Phrase("Peso Promedio (g)", parrafoNegro); tbl.AddCell(c1); c2.Phrase = new Phrase(decimal.Parse(item.PesoPromedio.ToString()).ToString("N"), parrafoNegro); tbl.AddCell(c2); c3.Phrase = new Phrase(" ", parrafoNegro); tbl.AddCell(c3); c1.Phrase = new Phrase("Uniformidad (%)", parrafoNegro); tbl.AddCell(c1); c2.Phrase = new Phrase(int.Parse(item.Uniformidad.ToString()).ToString("N"), parrafoNegro); tbl.AddCell(c2); c3.Phrase = new Phrase(" ", parrafoNegro); tbl.AddCell(c3); c1.Phrase = new Phrase("Sexo", parrafoNegro); tbl.AddCell(c1); c2.Phrase = new Phrase(item.Sexo, parrafoNegro); tbl.AddCell(c2); c3.Phrase = new Phrase(" ", parrafoNegro); tbl.AddCell(c3); // Agamos una lina en blanco c3.Phrase = new Phrase(" ", parrafoNegro); c3.Colspan = 3; tbl.AddCell(c3); doc.Add(tbl); tbl = new PdfPTable(new float[] { 47f, 6f, 47f }) { WidthPercentage = 100f }; var tbl1 = new PdfPTable(new float[] { 50f, 25f, 25f }) { WidthPercentage = 100f }; var tbl2 = new PdfPTable(new float[] { 50f, 25f, 25f }) { WidthPercentage = 100f }; c1 = new PdfPCell(); c1.Phrase = new Phrase("Criterio", parrafoNegro); c1.BackgroundColor = new BaseColor(211, 211, 211); c1.Padding = 6f; tbl1.AddCell(c1); tbl2.AddCell(c1); c2 = new PdfPCell(); c2.Phrase = new Phrase("Esperado", parrafoNegro); c2.HorizontalAlignment = Element.ALIGN_CENTER; c2.Padding = 6f; tbl1.AddCell(c2); tbl2.AddCell(c2); c3 = new PdfPCell(); c3.Phrase = new Phrase("Obtenido", parrafoNegro); c3.HorizontalAlignment = Element.ALIGN_CENTER; c3.Padding = 6f; tbl1.AddCell(c3); tbl2.AddCell(c3); int i = 1; foreach (BE_TxExamenFisicoPollitoResumen itemResumen in item.ListDetalleResumen) { c1.Phrase = new Phrase(itemResumen.DescripcionProceso, parrafoNegro); c2.Phrase = new Phrase(itemResumen.Esperado.ToString("N"), parrafoNegro); if (itemResumen.Obtenido < itemResumen.Esperado) { c3.Phrase = new Phrase(itemResumen.Obtenido.ToString("N"), parrafoRojo); } else { c3.Phrase = new Phrase(itemResumen.Obtenido.ToString("N"), parrafoNegro); } if ((i % 2) != 0) { tbl1.AddCell(c1); tbl1.AddCell(c2); tbl1.AddCell(c3); } else { tbl2.AddCell(c1); tbl2.AddCell(c2); tbl2.AddCell(c3); } i = i + 1; } tbl.AddCell(tbl1); c3 = new PdfPCell(); c3.Border = 0; tbl.AddCell(c3); tbl.AddCell(tbl2); c3.Phrase = new Phrase(" ", parrafoNegro); c3.Colspan = 3; tbl.AddCell(c3); doc.Add(tbl); tbl = new PdfPTable(new float[] { 20f, 15f, 75f }) { WidthPercentage = 100f }; c1 = new PdfPCell(); c1.Phrase = new Phrase("Calificación", parrafoNegro); c1.BackgroundColor = new BaseColor(211, 211, 211); c1.Padding = 6f; tbl.AddCell(c1); c2 = new PdfPCell(); c2.Phrase = new Phrase(decimal.Parse(item.Calificacion.ToString()).ToString("N"), parrafoNegro); c2.HorizontalAlignment = Element.ALIGN_CENTER; c2.Padding = 6f; tbl.AddCell(c2); c3 = new PdfPCell(); c3.Phrase = new Phrase(" ", parrafoNegro); c3.Border = 0; tbl.AddCell(c3); c1.Phrase = new Phrase("Resultado Calidad", parrafoNegro); c1.Padding = 6f; tbl.AddCell(c1); c2.Phrase = new Phrase(item.DescripcionCalidad, parrafoNegro); c2.BackgroundColor = new BaseColor(HexToColor(item.ColorCalidad)); c2.Padding = 6f; tbl.AddCell(c2); c3.Phrase = new Phrase(" ", parrafoNegro); tbl.AddCell(c3); // Agamos una lina en blanco c3.Phrase = new Phrase(" ", parrafoNegro); c3.Colspan = 3; tbl.AddCell(c3); doc.Add(tbl); tbl = new PdfPTable(new float[] { 20f, 25f, 55f }) { WidthPercentage = 100f }; c1 = new PdfPCell(); c1.Phrase = new Phrase("Calificación", parrafoNegro); c1.BackgroundColor = new BaseColor(211, 211, 211); c1.HorizontalAlignment = Element.ALIGN_CENTER; c1.Padding = 6f; tbl.AddCell(c1); c1.Phrase = new Phrase("Calidad de pollitos", parrafoNegro); tbl.AddCell(c1); c1 = new PdfPCell(); c1.Phrase = new Phrase(" ", parrafoNegro); c1.Border = 0; tbl.AddCell(c1); foreach (BE_Calidad itemCalidad in calidad) { c1 = new PdfPCell(); var rango = string.Format("{0} - {1}", itemCalidad.RangoInicial, itemCalidad.RangoFinal); c1.Phrase = new Phrase(rango, parrafoNegro); c1.BackgroundColor = new BaseColor(HexToColor(itemCalidad.Color)); c1.HorizontalAlignment = Element.ALIGN_CENTER; c1.Padding = 4f; tbl.AddCell(c1); c1.Phrase = new Phrase(itemCalidad.Descripcion, parrafoNegro); tbl.AddCell(c1); c1 = new PdfPCell(); c1.Phrase = new Phrase(" ", parrafoNegro); c1.Border = 0; tbl.AddCell(c1); } // Agamos una lina en blanco c1.Phrase = new Phrase(" ", parrafoNegro); c1.Colspan = 3; tbl.AddCell(c1); // Agamos una lina en blanco c1.Phrase = new Phrase(" ", parrafoNegro); c1.Colspan = 3; tbl.AddCell(c1); // Agamos una lina en blanco c1.Phrase = new Phrase(" ", parrafoNegro); c1.Colspan = 3; tbl.AddCell(c1); doc.Add(tbl); // Validamos si ingresaron imagenes var countFotos = item.ListDetalleFotos.Count(); iTextSharp.text.Image foto = null; if (countFotos > 0) { //doc.Add(new Phrase("\n")); doc.Add(new Phrase("Fotos", subTitulo)); doc.Add(new Phrase(" ")); tbl = new PdfPTable(new float[] { 50f, 50f }) { WidthPercentage = 100f }; c1 = new PdfPCell(); foreach (var detalle7 in item.ListDetalleFotos) { foto = ImagenBase64ToImagen(detalle7.Foto, 270f, 200f); if (foto != null) { c1 = new PdfPCell(foto); c1.HorizontalAlignment = Element.ALIGN_CENTER; c1.VerticalAlignment = Element.ALIGN_MIDDLE; c1.Border = 0; tbl.AddCell(c1); } } if ((countFotos % 2) != 0) { c1 = new PdfPCell(new Phrase(" ")); c1.Border = 0; tbl.AddCell(c1); } doc.Add(tbl); } doc.Add(new Phrase(" ")); tbl = new PdfPTable(new float[] { 45f, 10f, 45f }) { WidthPercentage = 100f }; c1 = new PdfPCell(); foto = ImagenBase64ToImagen(item.FirmaPlanta, 270f, 100f); c1 = new PdfPCell(foto); c1.HorizontalAlignment = Element.ALIGN_CENTER; c1.VerticalAlignment = Element.ALIGN_MIDDLE; c1.Border = 0; tbl.AddCell(c1); c1 = new PdfPCell(new Phrase(" ")); c1.Border = 0; tbl.AddCell(c1); foto = ImagenBase64ToImagen(item.FirmaInvetsa, 270f, 100f); c1 = new PdfPCell(foto); c1.HorizontalAlignment = Element.ALIGN_CENTER; c1.VerticalAlignment = Element.ALIGN_MIDDLE; c1.Border = 0; tbl.AddCell(c1); c1 = new PdfPCell(new Phrase("Responsable de Planta", parrafoNegro)) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE }; c1.Border = 0; c1.BorderWidthTop = 2f; tbl.AddCell(c1); c1 = new PdfPCell(new Phrase(" ")); c1.Border = 0; tbl.AddCell(c1); c1 = new PdfPCell(new Phrase("Responsable de Invetsa", parrafoNegro)) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE }; c1.Border = 0; c1.BorderWidthTop = 2f; tbl.AddCell(c1); c1 = new PdfPCell(new Phrase("Nombre: " + item.ResponsablePlanta, parrafoNegro)) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE }; c1.Border = 0; tbl.AddCell(c1); c1 = new PdfPCell(new Phrase(" ")); c1.Border = 0; tbl.AddCell(c1); c1 = new PdfPCell(new Phrase("Nombre: " + item.ResponsableInvetsa, parrafoNegro)) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE }; c1.Border = 0; tbl.AddCell(c1); doc.Add(tbl); write.Close(); doc.Close(); ms.Seek(0, SeekOrigin.Begin); var file = ms; return file; })); }
private void GeneratePDF() { rand[0] = (Convert.ToInt32(textbox.Text) * 1103515245) & 0x7fffffff; for (int i = 0; i < 49; i++) { rand[i + 1] = (rand[i] * 1103515245) & 0x7fffffff; } var paper1 = new Document(PageSize.A4, 60, 60, 80, 50); PdfWriter pdf = PdfWriter.GetInstance(paper1, new FileStream("paper1.pdf", FileMode.Create)); PageEventHelper pageEventHelper = new PageEventHelper(); pdf.PageEvent = pageEventHelper; paper1.Open(); Font roman = new Font(Font.FontFamily.TIMES_ROMAN, 10f); PdfPTable table = new PdfPTable(1); table.TotalWidth = 480f; table.LockedWidth = true; var p = new Paragraph(); p.Add(new Phrase("SECTION A(1) (35 marks)\n\n\n", new Font(Font.FontFamily.TIMES_ROMAN, 10f, Font.BOLD))); //Question 1 p.Add(new Phrase("\n1. Simplify ", roman)); string strquestion1 = GenerateQuestion(1); iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(new Uri(GenerateImage(strquestion1, "img1.png"))); label.Content = strquestion1; png.ScalePercent(10f); p.Add(new Chunk(png, 0, -9f)); p.Add(new Phrase(" and express your answer with positive indices.", roman)); //p.TabSettings = new TabSettings(); //p.Add(Chunk.TABBING); p.Add(new Chunk(new VerticalPositionMark())); p.Add(new Phrase("(3 marks)", roman)); p.Add(new Phrase("_\n\n\n", FontFactory.GetFont("Times New Roman", 10, Font.BOLD, new iTextSharp.text.BaseColor(255, 255, 255)))); for (int i = 0; i < 11; i++) { p.Add(new Phrase(" ____________________________________________________________________\n\n", new Font(Font.FontFamily.TIMES_ROMAN, 13f))); } //Question 2 p.Add(new Phrase("\n2. Make ", roman)); string strquestion2 = GenerateQuestion(2); png = iTextSharp.text.Image.GetInstance(new Uri(GenerateImage(strquestion2, "img2.png"))); png.ScalePercent(10f); if (strquestion2.Contains("y")) { p.Add(new Chunk(png, 0, -2f)); } else { p.Add(new Chunk(png, 0, 0)); } p.Add(new Phrase(" the subject of the formula ", roman)); string strquestion3 = GenerateQuestion(3); png = iTextSharp.text.Image.GetInstance(new Uri(GenerateImage(strquestion3, "img3.png"))); png.ScalePercent(10f); if (strquestion3.Contains("\\frac{")) { p.Add(new Chunk(png, 0, -7f)); } else { p.Add(new Chunk(png, 0, -2f)); } p.Add(new Phrase(" .", roman)); p.Add(new Chunk(new VerticalPositionMark())); p.Add(new Phrase("(3 marks)", roman)); p.Add(new Phrase("_\n\n\n", FontFactory.GetFont("Times New Roman", 10, Font.BOLD, new iTextSharp.text.BaseColor(255, 255, 255)))); for (int i = 0; i < 11; i++) { p.Add(new Phrase(" ____________________________________________________________________\n\n", new Font(Font.FontFamily.TIMES_ROMAN, 13f))); } PdfPCell content = new PdfPCell(new Phrase(p)); //content.Colspan = 4; table.AddCell(content); paper1.Add(table); Paragraph para = new Paragraph(new Phrase("Answers written in the margins will not be marked.", roman)); para.Add(new Chunk(new VerticalPositionMark())); para.Add(new Phrase("Seed: " + textbox.Text.ToString(), roman)); paper1.Add(para); //Paragraph password = new Paragraph(new Phrase("Password: "******"3. Factorize\n\n (a) ", roman)); string strquestion4 = GenerateQuestion(4); png = iTextSharp.text.Image.GetInstance(new Uri(GenerateImage(strquestion4, "img4.png"))); png.ScalePercent(10f); p.Add(new Chunk(png, 0, -2f)); p.Add(new Phrase(" ,\n\n (b) ", roman)); string strquestion5 = GenerateQuestion(5); png = iTextSharp.text.Image.GetInstance(new Uri(GenerateImage(strquestion5, "img5.png"))); png.ScalePercent(10f); p.Add(new Chunk(png, 0, -2f)); p.Add(new Phrase(" .", roman)); //p.TabSettings = new TabSettings(); //p.Add(Chunk.TABBING); p.Add(new Chunk(new VerticalPositionMark())); p.Add(new Phrase("(3 marks)", roman)); p.Add(new Phrase("_\n\n\n", FontFactory.GetFont("Times New Roman", 10, Font.BOLD, new iTextSharp.text.BaseColor(255, 255, 255)))); for (int i = 0; i < 11; i++) { p.Add(new Phrase(" ____________________________________________________________________\n\n", new Font(Font.FontFamily.TIMES_ROMAN, 13f))); } content = new PdfPCell(new Phrase(p)); //content.Colspan = 4; table.AddCell(content); paper1.Add(table); paper1.Add(para); paper1.Close(); pdfWebViewer.Navigate(System.AppDomain.CurrentDomain.BaseDirectory + "paper1.pdf"); }