Пример #1
0
        public async Task <IActionResult> ProductCard()
        {
            try
            {
                ViewBag.FileRefPath = base.JsReportFileRefPath;
                ViewBag.ItemCount   = 10;

                var header = await _jsReport.RenderViewToStringAsync(HttpContext, RouteData, "HeaderReport", new { });

                var footer = await _jsReport.RenderViewToStringAsync(HttpContext, RouteData, "FooterReport", new { });

                HttpContext.JsReportFeature().Recipe(jsreport.Types.Recipe.ChromePdf)
                .Configure((r) => r.Template.Chrome = new Chrome
                {
                    DisplayHeaderFooter = true,
                    HeaderTemplate      = header,
                    FooterTemplate      = footer,
                    Format       = _config["ReportSetting:Format"],
                    MarginTop    = "0.7cm",
                    MarginLeft   = _config["ReportSetting:MarginLeft"],
                    MarginBottom = _config["ReportSetting:MarginBottom"],
                    MarginRight  = _config["ReportSetting:MarginRight"]
                });

                return(await Task.Run(() => View(ProductCardModel.Example())));
            }
            catch (Exception ex)
            {
                string excLog = ex.Message;
                return(BadRequest());
            }
        }
Пример #2
0
        public async Task <IActionResult> PrintMachine(List <M_Machine> lstSelMc)   //List<M_Machine> lstSelMc
        {
            try
            {
                ViewBag.FileRefPath = base.JsReportFileRefPath;

                List <MachineLabelModel> printMcLabel = lstSelMc.ConvertAll(mc => new MachineLabelModel(mc));

                if (printMcLabel != null)
                {
                    ViewBag.ItemCount = printMcLabel.Count();
                }

                var header = await _jsReport.RenderViewToStringAsync(HttpContext, RouteData, "HeaderReport", new { });

                var footer = await _jsReport.RenderViewToStringAsync(HttpContext, RouteData, "FooterReport", new { });

                HttpContext.JsReportFeature().Recipe(jsreport.Types.Recipe.ChromePdf)
                .Configure((r) => r.Template.Chrome = new Chrome
                {
                    //Url = _hostingEnvironment.WebRootPath,
                    DisplayHeaderFooter = true,
                    HeaderTemplate      = header,
                    FooterTemplate      = footer,
                    Landscape           = true,
                    //Format = "A4",
                    //MarginTop = "0.7cm",
                    //MarginLeft = "0.7cm",
                    //MarginBottom = "0.7cm",
                    //MarginRight = "0.7cm"
                    Format       = _config["ReportSetting:Format"],
                    MarginTop    = _config["ReportSetting:MarginTop"],
                    MarginLeft   = _config["ReportSetting:MarginLeft"],
                    MarginBottom = _config["ReportSetting:MarginBottom"],
                    MarginRight  = _config["ReportSetting:MarginRight"]
                });

                return(await Task.Run(() => View(printMcLabel)));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { success = false, message = ex.Message }));
            }
        }
Пример #3
0
        public async Task <ActionResult> Invoice(string id)
        {
            var invoice = await _dbContext.Invoices
                          .Include(i => i.Coupon)
                          .Include(i => i.Items)
                          .Include(i => i.Team)
                          .FirstOrDefaultAsync(i => i.LinkId == id);

            if (invoice == null || string.IsNullOrWhiteSpace(id))
            {
                return(NotFound());
            }

            // look for the file on storage server first
            // use the link id, which should always be the most up to date
            var identifier = $"invoice-{invoice.LinkId}";

            var file = await _storageService.DownloadFile(identifier, StorageSettings.InvoicePdfContainerName);

            if (await file.ExistsAsync())
            {
                var stream = await file.OpenReadAsync();

                return(new FileStreamResult(stream, file.Properties.ContentType));
            }

            var footer = await _jsReportMvcService.RenderViewToStringAsync(HttpContext, RouteData, "InvoiceFooter", invoice);

            var request = new RenderRequest()
            {
                Template = new Template()
                {
                    Recipe = Recipe.ChromePdf,
                    Engine = Engine.None,
                    Chrome = new Chrome()
                    {
                        DisplayHeaderFooter = true,
                        HeaderTemplate      = "<div></div>", // use empty header
                        FooterTemplate      = footer,
                        MarginTop           = "1in",
                        MarginBottom        = "2.5in",
                        MarginLeft          = "25px",
                        MarginRight         = "25px",
                    },
                },
                Options = new RenderOptions()
                {
                    Debug = new DebugOptions()
                    {
                        LogsToResponseHeader = true,
                    },
                },
            };

            // generate pdf
            var report = await _jsReportMvcService.RenderViewAsync(HttpContext, request, RouteData, "Invoice", invoice);

            // save result to storage server for retrieval
            var uploadStream = new MemoryStream();
            await report.Content.CopyToAsync(uploadStream);

            var upload = new UploadRequest()
            {
                Identifier    = identifier,
                ContainerName = StorageSettings.InvoicePdfContainerName,
                ContentType   = report.Meta.ContentType,
                Data          = uploadStream,
            };
            await _storageService.UploadFiles(upload);

            // reset stream and return
            report.Content.Seek(0, SeekOrigin.Begin);
            return(new FileStreamResult(report.Content, report.Meta.ContentType));
        }