Ejemplo n.º 1
0
        public async Task <FileResult> PostPdfAutorizacion([FromBody] ResponseApiPma requestPma)
        {
            var list           = requestPma;
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Landscape,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 6
                },
                DocumentTitle = "Formato Legalizacion"
            };


            var templatePdfAutorizacion = new TemplatePdfAutorizacion();
            //var template= await templatePdfAutorizacion.GetHTMLString(requestPma,_hostingEnvironment.WebRootPath);

            var objectSettings = new ObjectSettings
            {
                PagesCount = true,
                // Page= "http://interedes.co/",
                HtmlContent = await templatePdfAutorizacion.GetHTMLString(requestPma, _hostingEnvironment.WebRootPath),
                WebSettings =
                {
                    DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css")
                },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = false },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = false, Center = "" }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            var file = _converter.Convert(pdf);

            /* var ruta= await postUploadImage(file);
             * var stream = new FileStream(_hostingEnvironment.WebRootPath+ruta,FileMode.Open);
             * HttpContext.Response.ContentType = "application/pdf";
             * return new FileStreamResult(stream, "application/pdf")
             * {
             *   FileDownloadName = "Formato_Autorizacion.pdf"
             * };
             */

            return(File(file, "application/pdf", "Formato_Autorizacion.pdf"));
            //return File(file, "application/pdf");
        }
Ejemplo n.º 2
0
        public async Task <FileResult> GetPdfAutorizacionExample()
        {
            var requestPma = new ResponseApiPma();

            requestPma.Email   = "*****@*****.**";
            requestPma.Formato = "P135-PYC-ADM-16-13-011";
            requestPma.Version = "Version";

            var cliente = new Cliente();

            cliente.Nombre   = "Nombre";
            cliente.Contrato = "Contrato";
            cliente.Proyecto = "Proyecto";


            var historias = new List <Historias>();

            for (var i = 0; i < 3; i++)
            {
                var historia1 = new Historias();
                historia1.Alimentacion = i;
                historia1.Alojamiento  = i;
                historia1.Destino      = "Destino";
                historia1.Estado       = "Estado";
                historia1.Fecha        = "Fecha";
                historia1.Miscelaneos  = i;
                historia1.Orden        = "Orden";
                historia1.Origen       = "Origen";
                historia1.Tarifa       = "Tarifa";
                historia1.Transporte   = i;
                historia1.Valor        = i;
                historias.Add(historia1);
            }

            var dataPdf = new List <DataRequest>();

            for (var i = 0; i < 2; i++)
            {
                var empleado = new Empleado();
                empleado.Apellidos = "Apellidos " + i;
                empleado.Cargo     = "Cargo";
                empleado.CC        = 1;
                empleado.CECO      = "CECO";
                empleado.Nombres   = "Nombres";
                empleado.Sucursal  = 2;

                var dataRequest1 = new DataRequest();
                dataRequest1.Fecha       = "Fecha";
                dataRequest1.Objeto      = "Objeta" + i;
                dataRequest1.FechaInicio = "FechaInicio";
                dataRequest1.FechaFin    = "FechaFin";
                dataRequest1.Consecutivo = "Consecutivo" + i;
                dataRequest1.SumAloj     = 1;
                dataRequest1.SumAlim     = 2;
                dataRequest1.SumMisc     = 3;
                dataRequest1.SumTran     = 4;
                dataRequest1.SumValor    = 4500;
                dataRequest1.Cliente     = cliente;
                dataRequest1.Empleado    = empleado;
                dataRequest1.Historias   = historias;
                dataPdf.Add(dataRequest1);
            }

            requestPma.Data = dataPdf;


            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Landscape,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 6
                },
                DocumentTitle = "Formato Autorizacion"
            };

            var templatePdfAutorizacion = new TemplatePdfAutorizacion();

            // var employees = DataStorage.GetAllEmployess();
            var objectSettings = new ObjectSettings
            {
                PagesCount = true,
                // Page= "http://interedes.co/",
                HtmlContent = await templatePdfAutorizacion.GetHTMLString(requestPma, _hostingEnvironment.WebRootPath),
                WebSettings =
                {
                    DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css")
                },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = false },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = false, Center = "" }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            var file = _converter.Convert(pdf);

            return(File(file, "application/pdf", "Formato_Legalizacion.pdf"));

            /*var ruta= await postUploadImage(file);
             *
             * return  TestDownload(_hostingEnvironment.WebRootPath+ruta,"Example.pdf");
             */


            /* var stream = new FileStream(_hostingEnvironment.WebRootPath+ruta,FileMode.Open);
             * return new FileStreamResult(stream, "application/pdf")
             * {
             *   FileDownloadName = "Example.pdf"
             * };*/
            /*
             *
             * var response = new HttpResponseMessage(HttpStatusCode.OK)
             * {
             *  Content = new ByteArrayContent(file)
             * };
             * response.Content = new ByteArrayContent(file);
             * response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
             * response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline")
             * {
             *  FileName = String.Format("AgencyID" + "userName" + DateTime.Now.ToString("MMMddyyyy_HHmmss"))
             *
             * };
             *
             * response.Headers.CacheControl = new CacheControlHeaderValue()
             * {
             *  MaxAge = new TimeSpan(0, 0, 60) // Cache for 30s so IE8 can open the PDF
             * };*/


            //return response;
            // return File(file, "application/pdf", "EmployeeReport.pdf");
            // return File(file, "application/pdf");
            //var outputStream = new MemoryStream();


            //HtmlCellTemplatePdfReport.CreateHtmlHeaderPdfReportStream(_hostingEnvironment.WebRootPath, outputStream);
            // var stream =  new FileStreamResult(outputStream, "application/pdf")
            //{
            //     FileDownloadName = "report.pdf"
            // };
            // return stream;
            //return for view online
            //var bytepdf= ReadToEnd(stream.FileStream);
            //return File(bytepdf, "application/pdf");
        }