private void ImprimirContratoO_L_PREIMPRESO(DataRow filaInfoContrato) { tools _tools = new tools(); Boolean CarnetIncluido = CheckBox_CON_CARNET_APARTE.Checked; String filename = "plantilla_contrato_preimpreso_obra_labor_sertempo_eys"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;FileName=" + filename + ".pdf"); Response.Clear(); Response.ContentType = "application/pdf"; iTextSharp.text.Document document = new iTextSharp.text.Document(new Rectangle(ancho, alto), v_pixeles(15), v_pixeles(15), v_pixeles(15), v_pixeles(15)); iTextSharp.text.pdf.PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream); pdfEvents PageEventHandler = new pdfEvents(); writer.PageEvent = PageEventHandler; document.Open(); String LABORA_EN = filaInfoContrato["RAZ_SOCIAL"].ToString().Trim().ToUpper(); String CARGO = filaInfoContrato["NOM_OCUPACION"].ToString().Trim().ToUpper(); String CC = filaInfoContrato["NUM_DOC_IDENTIDAD"].ToString().Trim().ToUpper(); String NOMBRE = filaInfoContrato["APELLIDOS"].ToString().Trim().ToUpper() + " " + filaInfoContrato["NOMBRES"].ToString().Trim().ToUpper(); String FIRMA_EMPLEADO = String.Empty; String VALIDO_HASTA = Convert.ToDateTime(filaInfoContrato["FECHA_TERMINA"]).ToLongDateString(); String EMPRESA_USUARIA = filaInfoContrato["RAZ_SOCIAL"].ToString().Trim().ToUpper(); String FECHA_INICIACION = Convert.ToDateTime(filaInfoContrato["FECHA_INICIA"]).ToLongDateString(); String SALARIO = "$ " + String.Format("{0:N2}",Convert.ToDecimal(filaInfoContrato["SALARIO"]).ToString()); String PERIODO_PAGO = DropDownList_PERIODO_PAGO.SelectedItem.Text; String SERVICIO_RESPECTIVO = filaInfoContrato["DESCRIPCION"].ToString().Trim().ToUpper(); String DESCRIPCION_CARGO = filaInfoContrato["DSC_FUNCIONES"].ToString().Trim().ToUpper(); String NOMBRE_TRABAJADOR = filaInfoContrato["APELLIDOS"].ToString().Trim().ToUpper() + " " + filaInfoContrato["NOMBRES"].ToString().Trim().ToUpper(); String CC_TRABAJADOR = filaInfoContrato["NUM_DOC_IDENTIDAD"].ToString().Trim().ToUpper(); String CARGO_TRABAJADOR = filaInfoContrato["NOM_OCUPACION"].ToString().Trim().ToUpper(); String DOMICILIO_EMPLEADOR; if (Session["idEmpresa"].ToString() == "1") { DOMICILIO_EMPLEADOR = tabla.VAR_DOMICILIO_SERTEMPO; } else { DOMICILIO_EMPLEADOR = tabla.VAR_DOMICILIO_EYS; } String DIAS = DateTime.Now.Day.ToString(); String MES = _tools.obtenerNombreMes(DateTime.Now.Month); String ANIO = DateTime.Now.Year.ToString().Substring(2, 2); Font letra; Phrase texto; PdfPTable tablaPdf; PdfPCell celda; float escalaFirma = 80; String dirImagenFirma; if (Session["idEmpresa"].ToString() == "1") { dirImagenFirma = Server.MapPath("~/imagenes/reportes/firma_contrato_empleador_sertempo.jpg"); } else { dirImagenFirma = Server.MapPath("~/imagenes/reportes/firma_contrato_empleador_eys.jpg"); } iTextSharp.text.Image imagenFirma = iTextSharp.text.Image.GetInstance(dirImagenFirma); imagenFirma.ScalePercent(escalaFirma); PdfContentByte cb = writer.DirectContent; if (CarnetIncluido == true) { cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 7); cb.BeginText(); cb.SetTextMatrix(v_pixeles(17), v_pixeles(10)); cb.ShowText(LABORA_EN); cb.EndText(); cb.BeginText(); cb.SetTextMatrix(v_pixeles(17), v_pixeles(15)); cb.ShowText(CARGO); cb.EndText(); cb.BeginText(); cb.SetTextMatrix(v_pixeles(17), v_pixeles(19)); cb.ShowText(CC); cb.EndText(); cb.BeginText(); cb.SetTextMatrix(v_pixeles(17), v_pixeles(24)); cb.ShowText(NOMBRE); cb.EndText(); cb.BeginText(); cb.SetTextMatrix(v_pixeles(133), v_pixeles(53)); cb.ShowText(FIRMA_EMPLEADO); cb.EndText(); cb.BeginText(); cb.SetTextMatrix(v_pixeles(133), v_pixeles(57)); cb.ShowText(VALIDO_HASTA); cb.EndText(); } cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 8); cb.BeginText(); cb.SetTextMatrix(v_pixeles(10), v_pixeles(234)); cb.ShowText(EMPRESA_USUARIA); cb.EndText(); cb.BeginText(); cb.SetTextMatrix(v_pixeles(140), v_pixeles(234)); cb.ShowText(FECHA_INICIACION); cb.EndText(); cb.BeginText(); cb.SetTextMatrix(v_pixeles(10), v_pixeles(242)); cb.ShowText(SALARIO); cb.EndText(); cb.BeginText(); cb.SetTextMatrix(v_pixeles(140), v_pixeles(242)); cb.ShowText(PERIODO_PAGO); cb.EndText(); tablaPdf = new PdfPTable(1); tablaPdf.TotalWidth = document.PageSize.Width - v_pixeles(20); letra = new Font(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 8); texto = new Phrase(SERVICIO_RESPECTIVO, letra); celda = new PdfPCell(texto); celda.Border = 0; celda.BorderWidth = 0; celda.HorizontalAlignment = 3; tablaPdf.AddCell(celda); tablaPdf.WriteSelectedRows(0, -1, v_pixeles(9), v_pixeles(259), cb); tablaPdf = new PdfPTable(1); tablaPdf.TotalWidth = document.PageSize.Width - v_pixeles(20); letra = new Font(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 8); texto = new Phrase(DESCRIPCION_CARGO, letra); celda = new PdfPCell(texto); celda.Border = 0; celda.BorderWidth = 0; celda.HorizontalAlignment = 3; tablaPdf.AddCell(celda); tablaPdf.WriteSelectedRows(0, -1, v_pixeles(9), v_pixeles(277), cb); cb.BeginText(); cb.SetTextMatrix(v_pixeles(10), v_pixeles(282)); cb.ShowText(NOMBRE_TRABAJADOR); cb.EndText(); cb.BeginText(); cb.SetTextMatrix(v_pixeles(140), v_pixeles(282)); cb.ShowText(CC_TRABAJADOR); cb.EndText(); cb.BeginText(); cb.SetTextMatrix(v_pixeles(10), v_pixeles(290)); cb.ShowText(CARGO_TRABAJADOR); cb.EndText(); cb.BeginText(); cb.SetTextMatrix(v_pixeles(98), v_pixeles(299)); cb.ShowText(DOMICILIO_EMPLEADOR); cb.EndText(); document.NewPage(); cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 6); cb.BeginText(); cb.SetTextMatrix(v_pixeles(45), v_pixeles(198)); cb.ShowText(DIAS); cb.EndText(); cb.BeginText(); cb.SetTextMatrix(v_pixeles(83), v_pixeles(198)); cb.ShowText(MES); cb.EndText(); cb.BeginText(); cb.SetTextMatrix(v_pixeles(122), v_pixeles(198)); cb.ShowText(ANIO); cb.EndText(); tablaPdf = new PdfPTable(1); tablaPdf.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; celda = new PdfPCell(imagenFirma); celda.Border = 0; celda.BorderWidth = 0; tablaPdf.AddCell(celda); tablaPdf.WriteSelectedRows(0, -1, v_pixeles(30), v_pixeles(111) + imagenFirma.Height, cb); document.Close(); writer.Close(); Response.End(); }
private void ImprimirContratoO_L_COMPLETO(DataRow filaInfoContrato) { tools _tools = new tools(); Boolean CarnetIncluido = CheckBox_CON_CARNET_APARTE.Checked; StreamReader archivo; if (Session["idEmpresa"].ToString() == "1") { if (CarnetIncluido == true) { archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\contrato_sertempo_obra_labor.htm")); } else { archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\contrato_sertempo_obra_labor_carnet_aparte.htm")); } } else { if (CarnetIncluido == true) { archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\contrato_eys_labor_contratada.htm")); } else { archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\contrato_eys_labor_contratada_carnet_aparte.htm")); } } String html = archivo.ReadToEnd(); archivo.Dispose(); archivo.Close(); String filename; if (Session["idEmpresa"].ToString() == "1") { html = html.Replace("[DIR_LOGO_EMPLEADOR]", tabla.DIR_IMAGENES_PARA_PDF + "/logo_sertempo.png"); html = html.Replace("[MENSAJE_LOGO]", "SERVICIOS TEMPORALES PROFESIONALES"); html = html.Replace("[NOMBRE_EMPLEADOR]", tabla.VAR_NOMBRE_SERTEMPO); html = html.Replace("[DOMICILO_EMPLEADOR]", tabla.VAR_DOMICILIO_SERTEMPO); html = html.Replace("[DESCRIPCION_CARGO]", filaInfoContrato["DSC_FUNCIONES"].ToString().Trim().ToUpper()); html = html.Replace("[SERVICIO_RESPECTIVO]", filaInfoContrato["DESCRIPCION"].ToString().Trim().ToUpper()); html = html.Replace("[EMPRESA_USUARIA]", filaInfoContrato["RAZ_SOCIAL"].ToString().Trim().ToUpper()); html = html.Replace("[DESCRIPCION_SALARIO]", filaInfoContrato["DESCRIPCION_SALARIO"].ToString().Trim().ToUpper()); html = html.Replace("[DIR_FIRMA_EMPLEADOR]", tabla.DIR_IMAGENES_PARA_PDF + "/firma_autos_recomendacion.jpg"); filename = "contrato_sertempo"; } else { html = html.Replace("[DIR_LOGO_EMPLEADOR]", tabla.DIR_IMAGENES_PARA_PDF + "/logo_eficiencia.jpg"); html = html.Replace("[NOMBRE_EMPLEADOR]", tabla.VAR_NOMBRE_EYS); html = html.Replace("[DOMICILO_EMPLEADOR]", tabla.VAR_DOMICILIO_EYS); html = html.Replace("[FUNCION_CARGO]", filaInfoContrato["DSC_FUNCIONES"].ToString().Trim().ToUpper()); html = html.Replace("[ACTIVIDAD_CONTRATADA]", filaInfoContrato["DSC_FUNCIONES"].ToString().Trim().ToUpper()); html = html.Replace("[EMPRESA_DESTACA]", filaInfoContrato["RAZ_SOCIAL"].ToString().Trim().ToUpper()); html = html.Replace("[DESCRIPCION_SALARIO]", filaInfoContrato["DESCRIPCION_SALARIO"].ToString().Trim().ToUpper()); html = html.Replace("[DIR_FIRMA_EMPLEADOR]", tabla.DIR_IMAGENES_PARA_PDF + "/firma_autos_recomendacion.jpg"); filename = "contrato_eys"; } html = html.Replace("[CARGO_TRABAJADOR]", filaInfoContrato["NOM_OCUPACION"].ToString().Trim().ToUpper()); html = html.Replace("[NOMBRE_TRABAJADOR]", filaInfoContrato["APELLIDOS"].ToString().Trim().ToUpper() + " " + filaInfoContrato["NOMBRES"].ToString().Trim().ToUpper()); html = html.Replace("[TIPO_DOCUMENTO_IDENTIDAD]", filaInfoContrato["TIP_DOC_IDENTIDAD"].ToString().Trim().ToUpper()); html = html.Replace("[DOC_IDENTIFICACION]", filaInfoContrato["NUM_DOC_IDENTIDAD"].ToString().Trim().ToUpper()); html = html.Replace("[SALARIO]", String.Format("$ {0:N2}", Convert.ToDecimal(filaInfoContrato["SALARIO"]).ToString())); html = html.Replace("[PERIODO_PAGO]", DropDownList_PERIODO_PAGO.SelectedItem.Text); html = html.Replace("[FECHA_INICIACION]", Convert.ToDateTime(filaInfoContrato["FECHA_INICIA"]).ToLongDateString()); html = html.Replace("[CARNE_VALIDO_HASTA]", Convert.ToDateTime(filaInfoContrato["FECHA_TERMINA"]).ToLongDateString()); usuario _usuario = new usuario(Session["idEmpresa"].ToString()); DataTable tablaInfoUsuario = _usuario.ObtenerInicioSesionPorUsuLog(Session["USU_LOG"].ToString()); if (tablaInfoUsuario.Rows.Count <= 0) { html = html.Replace("[CIUDAD_FIRMA]", "Desconocida"); } else { DataRow filaInfoUsuario = tablaInfoUsuario.Rows[0]; html = html.Replace("[CIUDAD_FIRMA]", filaInfoUsuario["NOMBRE_CIUDAD"].ToString()); } DateTime fechaHoy = DateTime.Now; html = html.Replace("[DIAS_FIRMA]", fechaHoy.Day.ToString()); html = html.Replace("[MES_FIRMA]", _tools.obtenerNombreMes(fechaHoy.Month)); html = html.Replace("[ANNO_FIRMA]", fechaHoy.Year.ToString()); HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;FileName=" + filename + ".pdf"); Response.Clear(); Response.ContentType = "application/pdf"; iTextSharp.text.Document document = new iTextSharp.text.Document(new Rectangle(612, 936), 15, 15, 10, 10); iTextSharp.text.pdf.PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream); pdfEvents PageEventHandler = new pdfEvents(); writer.PageEvent = PageEventHandler; PageEventHandler.tipoDocumento = "contrato"; document.Open(); String tempFile = Path.GetTempFileName(); using (StreamWriter tempwriter = new StreamWriter(tempFile, false)) { tempwriter.Write(html); } List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StreamReader(tempFile), new StyleSheet()); foreach (IElement element in htmlarraylist) { document.Add(element); } document.Close(); writer.Close(); Response.End(); File.Delete(tempFile); }
/// <summary> /// hecho por cesar pulido /// el dia 19 de diciembre de 2012 /// para generar el archivo del contrato /// </summary> /// <param name="filaInfoContrato"></param> /// <returns></returns> private byte[] ImprimirContratoO_L_COMPLETO(DataRow filaInfoContrato) { tools _tools = new tools(); Boolean CarnetIncluido = false; //En esta variable cargamos el documento plantilla segun la empresa de session StreamReader archivo; if (Session["idEmpresa"].ToString() == "1") { if (CarnetIncluido == true) { archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\contrato_sertempo_obra_labor.htm")); } else { archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\contrato_sertempo_obra_labor_carnet_aparte.htm")); } } else { if (CarnetIncluido == true) { archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\contrato_eys_labor_contratada.htm")); } else { archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\contrato_eys_labor_contratada_carnet_aparte.htm")); } } String html = archivo.ReadToEnd(); archivo.Dispose(); archivo.Close(); if (Session["idEmpresa"].ToString() == "1") { html = html.Replace("[DIR_LOGO_EMPLEADOR]", tabla.DIR_IMAGENES_PARA_PDF + "/logo_sertempo.png"); html = html.Replace("[MENSAJE_LOGO]", "SERVICIOS TEMPORALES PROFESIONALES"); html = html.Replace("[NOMBRE_EMPLEADOR]", tabla.VAR_NOMBRE_SERTEMPO); html = html.Replace("[DOMICILO_EMPLEADOR]", tabla.VAR_DOMICILIO_SERTEMPO); html = html.Replace("[DESCRIPCION_CARGO]", filaInfoContrato["DSC_FUNCIONES"].ToString().Trim().ToUpper()); html = html.Replace("[SERVICIO_RESPECTIVO]", filaInfoContrato["DESCRIPCION"].ToString().Trim().ToUpper()); html = html.Replace("[EMPRESA_USUARIA]", filaInfoContrato["RAZ_SOCIAL"].ToString().Trim().ToUpper()); html = html.Replace("[DIR_FIRMA_EMPLEADOR]", tabla.DIR_IMAGENES_PARA_PDF + "/firma_contrato_empleador_sertempo.jpg"); } else { html = html.Replace("[DIR_LOGO_EMPLEADOR]", tabla.DIR_IMAGENES_PARA_PDF + "/logo_eficiencia.jpg"); html = html.Replace("[NOMBRE_EMPLEADOR]", tabla.VAR_NOMBRE_EYS); html = html.Replace("[DOMICILO_EMPLEADOR]", tabla.VAR_DOMICILIO_EYS); html = html.Replace("[FUNCION_CARGO]", filaInfoContrato["DSC_FUNCIONES"].ToString().Trim().ToUpper()); html = html.Replace("[ACTIVIDAD_CONTRATADA]", filaInfoContrato["DSC_FUNCIONES"].ToString().Trim().ToUpper()); html = html.Replace("[EMPRESA_DESTACA]", filaInfoContrato["RAZ_SOCIAL"].ToString().Trim().ToUpper()); html = html.Replace("[DIR_FIRMA_EMPLEADOR]", tabla.DIR_IMAGENES_PARA_PDF + "/firma_contrato_empleador_eys.jpg"); } html = html.Replace("[CARGO_TRABAJADOR]", filaInfoContrato["NOM_OCUPACION"].ToString().Trim().ToUpper()); html = html.Replace("[NOMBRE_TRABAJADOR]", filaInfoContrato["APELLIDOS"].ToString().Trim().ToUpper() + " " + filaInfoContrato["NOMBRES"].ToString().Trim().ToUpper()); html = html.Replace("[TIPO_DOCUMENTO_IDENTIDAD]", filaInfoContrato["TIP_DOC_IDENTIDAD"].ToString().Trim().ToUpper()); html = html.Replace("[DOC_IDENTIFICACION]", filaInfoContrato["NUM_DOC_IDENTIDAD"].ToString().Trim().ToUpper()); html = html.Replace("[SALARIO]", Convert.ToDecimal(filaInfoContrato["SALARIO"]).ToString()); html = html.Replace("[PERIODO_PAGO]", "??"); html = html.Replace("[FECHA_INICIACION]", Convert.ToDateTime(filaInfoContrato["FECHA_INICIA"]).ToLongDateString()); html = html.Replace("[CARNE_VALIDO_HASTA]", Convert.ToDateTime(filaInfoContrato["FECHA_TERMINA"]).ToLongDateString()); //esto es para obtener la ciudad de impresión del contrato //OBTENEMOS LA CIUDAD DE FIRMA, DESDE LA CIUDAD DEL USU_LOG usuario _usuario = new usuario(Session["idEmpresa"].ToString()); DataTable tablaInfoUsuario = _usuario.ObtenerInicioSesionPorUsuLog(Session["USU_LOG"].ToString()); if (tablaInfoUsuario.Rows.Count <= 0) { html = html.Replace("[CIUDAD_FIRMA]", "Desconocida"); } else { DataRow filaInfoUsuario = tablaInfoUsuario.Rows[0]; html = html.Replace("[CIUDAD_FIRMA]", filaInfoUsuario["NOMBRE_CIUDAD"].ToString()); } DateTime fechaHoy = DateTime.Now; html = html.Replace("[DIAS_FIRMA]", fechaHoy.Day.ToString()); html = html.Replace("[MES_FIRMA]", _tools.obtenerNombreMes(fechaHoy.Month)); html = html.Replace("[ANNO_FIRMA]", fechaHoy.Year.ToString()); //creamos un configuramos el documento de pdf //(tamaño de la hoja,margen izq, margen der, margin arriba margen abajo) iTextSharp.text.Document document = new iTextSharp.text.Document(new Rectangle(612, 936), 15, 15, 5, 15); using (MemoryStream streamArchivo = new MemoryStream()) { iTextSharp.text.pdf.PdfWriter writer = PdfWriter.GetInstance(document, streamArchivo); // Our custom Header and Footer is done using Event Handler pdfEvents PageEventHandler = new pdfEvents(); writer.PageEvent = PageEventHandler; PageEventHandler.tipoDocumento = "contrato"; document.Open(); //capturamos el archivo temporal del response String tempFile = Path.GetTempFileName(); //y lo llenamos con el html de la plantilla using (StreamWriter tempwriter = new StreamWriter(tempFile, false)) { tempwriter.Write(html); } //leeemos el archivo temporal y lo colocamos en el documento de pdf List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StreamReader(tempFile), new StyleSheet()); foreach (IElement element in htmlarraylist) { if (element.Chunks.Count > 0) { if (element.Chunks[0].Content == "linea para paginacion de pdf") { document.NewPage(); } else { document.Add(element); } } else { document.Add(element); } } //limpiamos todo document.Close(); writer.Close(); return streamArchivo.ToArray(); } }
/// <summary> /// hecho por cesar pulido /// el dia 9 de diciembre de 2012 /// para obtener el archivo de las clausulas /// </summary> /// <returns></returns> public byte[] GenerarPDFClausulas(Decimal ID_CONTRATO) { //obtenemos la informacion necesaria de las clausulas registroContrato _registroContrato = new registroContrato(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString()); DataTable tablaInfoClausulas = _registroContrato.ObtenerInfoParaImprimirClausulas(ID_CONTRATO); if (tablaInfoClausulas.Rows.Count > 0) { tools _tools = new tools(); //como existen clausulas antes de mostrarlas se debe actualizar el estado de impresion de clausulas DataTable tablaCon = _registroContrato.ObtenerConRegContratosPorRegistro(Convert.ToInt32(ID_CONTRATO)); DataRow fila = tablaCon.Rows[0]; //En esta variable cargamos el documento plantilla StreamReader archivo_original = new StreamReader(Server.MapPath(@"~\plantillas_reportes\clausulas.htm")); String html_clausula = archivo_original.ReadToEnd(); archivo_original.Dispose(); archivo_original.Close(); String html_completo = "<html><body>"; Int32 contadorClausulas = 0; //tenemos que recorrer todas las clausulas e imprimirlas en hojas diferentes pero un mismo documento foreach (DataRow filaClausula in tablaInfoClausulas.Rows) { //como se tiene un clausula entonces al html_compleo le adicionamos una plantilla contenido de clausula if (contadorClausulas == 0) { html_completo = html_clausula; } else { html_completo += "<div>linea para paginacion de pdf</div>"; html_completo += html_clausula; } //despues de haber agregado la plantilla se procede a reemplazar los tags if (Session["idEmpresa"].ToString() == "1") { html_completo = html_completo.Replace("[NOMBRE_EMPRESA]", tabla.VAR_NOMBRE_SERTEMPO); } else { html_completo = html_completo.Replace("[NOMBRE_EMPRESA]", tabla.VAR_NOMBRE_EYS); } html_completo = html_completo.Replace("[NOMBRE_TRABAJADOR]", filaClausula["NOMBRES"].ToString().Trim() + " " + filaClausula["APELLIDOS"].ToString().Trim()); html_completo = html_completo.Replace("[NOMBRE_CLAUSULA]", filaClausula["NOMBRE"].ToString().Trim()); html_completo = html_completo.Replace("[ENCABEZADO_CLAUSULA]", filaClausula["ENCABEZADO"].ToString().Trim()); html_completo = html_completo.Replace("[CONTENIDO_CLAUSULA]", filaClausula["DESCRIPCION"].ToString().Trim()); html_completo = html_completo.Replace("[CIUDAD_FIRMA]", "BOGOTA"); html_completo = html_completo.Replace("[DIAS]", DateTime.Now.Day.ToString()); html_completo = html_completo.Replace("[MES]", _tools.obtenerNombreMes(DateTime.Now.Month)); html_completo = html_completo.Replace("[ANNO]", DateTime.Now.Year.ToString()); contadorClausulas += 1; } html_completo += "</body></html>"; //creamos un configuramos el documento de pdf //(tamaño de la hoja,margen izq, margen der, margin arriba margen abajo) iTextSharp.text.Document document = new iTextSharp.text.Document(new Rectangle(595, 842), 40, 40, 80, 40); using (MemoryStream streamArchivo = new MemoryStream()) { iTextSharp.text.pdf.PdfWriter writer = PdfWriter.GetInstance(document, streamArchivo); // Our custom Header and Footer is done using Event Handler pdfEvents PageEventHandler = new pdfEvents(); writer.PageEvent = PageEventHandler; // Define the page header // Define the page header if (Session["idEmpresa"].ToString() == "1") { PageEventHandler.dirImagenHeader = Server.MapPath("~/imagenes/reportes/logo_sertempo.png"); } else { PageEventHandler.dirImagenHeader = Server.MapPath("~/imagenes/reportes/logo_eficiencia.png"); } PageEventHandler.fechaImpresion = DateTime.Now; PageEventHandler.tipoDocumento = "clausula"; document.Open(); //capturamos el archivo temporal del response String tempFile = Path.GetTempFileName(); //y lo llenamos con el html de la plantilla using (StreamWriter tempwriter = new StreamWriter(tempFile, false)) { tempwriter.Write(html_completo); } //leeemos el archivo temporal y lo colocamos en el documento de pdf List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StreamReader(tempFile), new StyleSheet()); foreach (IElement element in htmlarraylist) { if (element.Chunks.Count > 0) { if (element.Chunks[0].Content == "linea para paginacion de pdf") { document.NewPage(); } else { document.Add(element); } } else { document.Add(element); } } //limpiamos todo document.Close(); writer.Close(); return streamArchivo.ToArray(); } } else { return null; } }
private void previsualizar_clausula(Decimal ID_CON_REG_CLAUSULAS_PERFIL) { condicionesContratacion _condicionesContratacion = new condicionesContratacion(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString()); DataTable tablaInfoClausula = _condicionesContratacion.obtenerClausulasPorIdCluasula(ID_CON_REG_CLAUSULAS_PERFIL); DataRow filaInfo = tablaInfoClausula.Rows[0]; StreamReader archivo = new StreamReader(Server.MapPath(@"~\plantillas_reportes\clausulas.htm")); tools _tools = new tools(); String html_completo = "<html><body>"; html_completo += archivo.ReadToEnd(); html_completo += "</body></html>"; archivo.Dispose(); archivo.Close(); if (Session["idEmpresa"].ToString() == "1") { html_completo = html_completo.Replace("[NOMBRE_EMPRESA]", tabla.VAR_NOMBRE_SERTEMPO); } else { html_completo = html_completo.Replace("[NOMBRE_EMPRESA]", tabla.VAR_NOMBRE_EYS); } html_completo = html_completo.Replace("[NOMBRE_TRABAJADOR]", "NOMBRE DEL TRABAJADOR"); html_completo = html_completo.Replace("[NOMBRE_CLAUSULA]", filaInfo["NOMBRE"].ToString()); html_completo = html_completo.Replace("[ENCABEZADO_CLAUSULA]", filaInfo["ENCABEZADO"].ToString()); html_completo = html_completo.Replace("[CONTENIDO_CLAUSULA]", filaInfo["DESCRIPCION"].ToString()); usuario _usuario = new usuario(Session["idEmpresa"].ToString()); DataTable tablaInfoUsuario = _usuario.ObtenerInicioSesionPorUsuLog(Session["USU_LOG"].ToString()); if (tablaInfoUsuario.Rows.Count <= 0) { html_completo = html_completo.Replace("[CIUDAD_FIRMA]", "Desconocida"); } else { DataRow filaInfoUsuario = tablaInfoUsuario.Rows[0]; html_completo = html_completo.Replace("[CIUDAD_FIRMA]", filaInfoUsuario["NOMBRE_CIUDAD"].ToString()); } html_completo = html_completo.Replace("[DIAS]", DateTime.Now.Day.ToString()); html_completo = html_completo.Replace("[MES]", _tools.obtenerNombreMes(DateTime.Now.Month)); html_completo = html_completo.Replace("[ANNO]", DateTime.Now.Year.ToString()); String filename = "previsulizador_clausula"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;FileName=" + filename + ".pdf"); Response.Clear(); Response.ContentType = "application/pdf"; iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.A4, 40, 40, 80, 40); iTextSharp.text.pdf.PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream); pdfEvents PageEventHandler = new pdfEvents(); writer.PageEvent = PageEventHandler; if (Session["idEmpresa"].ToString() == "1") { PageEventHandler.dirImagenHeader = Server.MapPath("~/imagenes/reportes/logo_sertempo.png"); } else { PageEventHandler.dirImagenHeader = Server.MapPath("~/imagenes/reportes/logo_eficiencia.png"); } PageEventHandler.fechaImpresion = DateTime.Now; PageEventHandler.tipoDocumento = "clausula"; document.Open(); String tempFile = Path.GetTempFileName(); using (StreamWriter tempwriter = new StreamWriter(tempFile, false)) { tempwriter.Write(html_completo); } List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StreamReader(tempFile), new StyleSheet()); foreach (IElement element in htmlarraylist) { document.Add(element); } document.Close(); writer.Close(); Response.End(); File.Delete(tempFile); }
protected void Button_CLAUSULAS_Click(object sender, EventArgs e) { Decimal ID_CONTRATO = Convert.ToDecimal(HiddenField_ID_CONTRATO.Value); registroContrato _registroContrato = new registroContrato(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString()); DataTable tablaInfoClausulas = _registroContrato.ObtenerInfoParaImprimirClausulas(Convert.ToDecimal(HiddenField_ID_CONTRATO.Value)); if (tablaInfoClausulas.Rows.Count <= 0) { if (_registroContrato.MensajeError != null) { Informar(Panel_MENSAJE_IMPRESIONES_BASICAS, Label_MENSAJE_IMPRESIONES_BASICAS, _registroContrato.MensajeError, Proceso.Error); } else { DataTable tablaCon = _registroContrato.ObtenerConRegContratosPorRegistro(Convert.ToInt32(ID_CONTRATO)); DataRow fila = tablaCon.Rows[0]; _registroContrato.ActualizarConRegContratosImpresos(Convert.ToInt32(ID_CONTRATO), fila["CONTRATO_IMPRESO"].ToString(), "S"); Informar(Panel_MENSAJE_IMPRESIONES_BASICAS, Label_MENSAJE_IMPRESIONES_BASICAS, "ADVERTENCIA: No existen clausulas para este contrato y perfil, puede continuar, con los siguientes tramites.", Proceso.Error); } } else { tools _tools = new tools(); DataTable tablaCon = _registroContrato.ObtenerConRegContratosPorRegistro(Convert.ToInt32(ID_CONTRATO)); DataRow fila = tablaCon.Rows[0]; _registroContrato.ActualizarConRegContratosImpresos(Convert.ToInt32(ID_CONTRATO), fila["CONTRATO_IMPRESO"].ToString(), "S"); StreamReader archivo_original = new StreamReader(Server.MapPath(@"~\plantillas_reportes\clausulas.htm")); String html_clausula = archivo_original.ReadToEnd(); archivo_original.Dispose(); archivo_original.Close(); String html_completo = "<html><body>"; Int32 contadorClausulas = 0; foreach (DataRow filaClausula in tablaInfoClausulas.Rows) { if (contadorClausulas == 0) { html_completo = html_clausula; } else { html_completo += "<div>linea para paginacion de pdf</div>"; html_completo += html_clausula; } if (Session["idEmpresa"].ToString() == "1") { html_completo = html_completo.Replace("[NOMBRE_EMPRESA]", tabla.VAR_NOMBRE_SERTEMPO); } else { html_completo = html_completo.Replace("[NOMBRE_EMPRESA]", tabla.VAR_NOMBRE_EYS); } html_completo = html_completo.Replace("[NOMBRE_TRABAJADOR]", filaClausula["NOMBRES"].ToString().Trim() + " " + filaClausula["APELLIDOS"].ToString().Trim()); html_completo = html_completo.Replace("[NOMBRE_CLAUSULA]", filaClausula["NOMBRE"].ToString().Trim()); html_completo = html_completo.Replace("[ENCABEZADO_CLAUSULA]", filaClausula["ENCABEZADO"].ToString().Trim()); html_completo = html_completo.Replace("[CONTENIDO_CLAUSULA]", filaClausula["DESCRIPCION"].ToString().Trim()); html_completo = html_completo.Replace("[DIAS]", DateTime.Now.Day.ToString()); html_completo = html_completo.Replace("[MES]", _tools.obtenerNombreMes(DateTime.Now.Month)); html_completo = html_completo.Replace("[ANNO]", DateTime.Now.Year.ToString()); contadorClausulas += 1; } html_completo += "</body></html>"; String filename = "clausulas_contrato_" + ID_CONTRATO.ToString(); HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;FileName=" + filename + ".pdf"); Response.Clear(); Response.ContentType = "application/pdf"; iTextSharp.text.Document document = new iTextSharp.text.Document(new Rectangle(595, 842), 40, 40, 80, 40); iTextSharp.text.pdf.PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream); pdfEvents PageEventHandler = new pdfEvents(); writer.PageEvent = PageEventHandler; if (Session["idEmpresa"].ToString() == "1") { PageEventHandler.dirImagenHeader = Server.MapPath("~/imagenes/reportes/logo_sertempo.png"); } else { PageEventHandler.dirImagenHeader = Server.MapPath("~/imagenes/reportes/logo_eficiencia.png"); } PageEventHandler.fechaImpresion = DateTime.Now; PageEventHandler.tipoDocumento = "clausula"; document.Open(); String tempFile = Path.GetTempFileName(); using (StreamWriter tempwriter = new StreamWriter(tempFile, false)) { tempwriter.Write(html_completo); } List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StreamReader(tempFile), new StyleSheet()); foreach (IElement element in htmlarraylist) { if (element.Chunks.Count > 0) { if (element.Chunks[0].Content == "linea para paginacion de pdf") { document.NewPage(); } else { document.Add(element); } } else { document.Add(element); } } document.Close(); writer.Close(); Response.End(); File.Delete(tempFile); } }