Exemplo n.º 1
0
 public ActionResult Edit(ContratosWebModel model)
 {
     if (model.Edit())
     {
         return(Json(new JavaScriptSerializer().Serialize(model)));
     }
     return(View());
 }
Exemplo n.º 2
0
        public void ConvertPDF()
        {
            if ((sesion = SessionDB.start(Request, Response, false, db, SESSION_BEHAVIOR.AJAX)) == null)
            {
                return;
            }

            // convert HTML to PDF
            byte[] pdfBuffer = null;

            // convert HTML code
            ContratosWebModel conModel = new ContratosWebModel();

            conModel.Clave = sesion.vdata["CVE_CONTRATO"];
            conModel.Edit();
            string htmlCode = HttpUtility.UrlDecode(conModel.Formato, System.Text.Encoding.Default);

            ContratosWebPDFModel model = new ContratosWebPDFModel();

            model.Sede       = sesion.vdata["Sede"]; // from combobox Sedes
            model.IDSIU      = sesion.vdata["IDSIU"];
            model.PERIDO     = sesion.vdata["PERIODO"];
            model.CVE_SEDE   = sesion.vdata["CVE_SEDE"]; // from QEntregaContratos01
            model.ID_ESQUEMA = sesion.vdata["ID_ESQUEMA"];

            model.getDatos();
            htmlCode = model.fill(htmlCode);

            string htmlString = htmlCode;
            string baseUrl    = "";// collection["TxtBaseUrl"];

            //string thisPageUrl = this.ControllerContext.HttpContext.Request.Url.AbsoluteUri;
            //string baseUrl = thisPageUrl.Substring(0, thisPageUrl.Length - "ConstanciaRetencion".Length);

            string      pdf_page_size = "A4";
            PdfPageSize pageSize      = (PdfPageSize)Enum.Parse(typeof(PdfPageSize),
                                                                pdf_page_size, true);

            string             pdf_orientation = "Portrait";
            PdfPageOrientation pdfOrientation  =
                (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation),
                                               pdf_orientation, true);

            // instantiate a html to pdf converter object
            HtmlToPdf converter = new HtmlToPdf();

            // license key
            GlobalProperties.LicenseKey = "KgEbChgfGwoZGx0fChsSBBoKGRsEGxgEExMTEw==";

            // set converter options
            converter.Options.PdfPageSize        = pageSize;
            converter.Options.PdfPageOrientation = pdfOrientation;
            converter.Options.WebPageWidth       = Convert.ToInt32(1024);
            converter.Options.WebPageHeight      = Convert.ToInt32(0);
            converter.Options.MarginTop          = 35;
            converter.Options.MarginBottom       = 35;

            PdfDocument doc = converter.ConvertHtmlString(htmlString, baseUrl);

            pdfBuffer = doc.Save();

            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "inline; filename=ConstanciaRetencion.pdf");
            Response.BinaryWrite(pdfBuffer);
            doc.Close();
        }