Ejemplo n.º 1
0
        public override void ExecuteResult(ControllerContext context)
        {
            IView       viewEngineResult;
            ViewContext viewContext;

            if (ViewName == null)
            {
                ViewName = context.RouteData.GetRequiredString("action");
            }

            context.Controller.ViewData.Model = Model;


            if (context.HttpContext.Request.QueryString["html"] != null &&
                context.HttpContext.Request.QueryString["html"].ToLower().Equals("true"))
            {
                RenderHtmlOutput(context);
            }
            else
            {
                if (!String.IsNullOrEmpty(FileDownloadName))
                {
                    context.HttpContext.Response.AddHeader("content-disposition",
                                                           "attachment; filename=" + FileDownloadName);
                }

                new FileContentResult(context.GeneratePdf(Model, ViewName, ConfigureSettings), "application/pdf")
                .ExecuteResult(context);
            }
        }
Ejemplo n.º 2
0
        public ActionResult SaveToAppData()
        {
            var model = new PdfExample
            {
                Heading = "Heading",
                Items   = new List <BasketItem>
                {
                    new BasketItem
                    {
                        Id          = 1,
                        Description = "Item 1",
                        Price       = 1.99m
                    },
                    new BasketItem
                    {
                        Id          = 2,
                        Description = "Item 2",
                        Price       = 2.99m
                    }
                }
            };

            byte[] pdfOutput = ControllerContext.GeneratePdf(model, "IndexWithAccessToDocumentAndWriter");
            string fullPath  = Server.MapPath("~/App_Data/FreshlyMade.pdf");

            if (SysIO.File.Exists(fullPath))
            {
                SysIO.File.Delete(fullPath);
            }
            SysIO.File.WriteAllBytes(fullPath, pdfOutput);

            return(View("SaveToAppData"));
        }
Ejemplo n.º 3
0
        public ActionResult U65Certificate(int id)
        {
            if (id > 0)
            {
                var model = BCBSDataAccess.U65GetDataForCertificate(id);
                if (model != null)
                {
                    model.DateofCompletion = model.DateofCompletion;

                    string fileName = string.Empty;
                    byte[] bytes    = new byte[0];
                    var    response = new FileContentResult(bytes, "application/octet-stream");
                    bytes = ControllerContext.GeneratePdf(model, "_U65CertificatePDF");

                    Font footerFont = FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLACK);
                    using (MemoryStream stream = new MemoryStream())
                    {
                        Document  document = new Document(PageSize.A4_LANDSCAPE);
                        PdfWriter writer   = PdfWriter.GetInstance(document, stream);
                        PdfReader reader   = new PdfReader(bytes);
                        using (PdfStamper stamper = new PdfStamper(reader, stream))
                        {
                            stamper.AcroFields.SetFieldProperty("SomeDateField", "textsize", 1f, null);
                            int pages = reader.NumberOfPages;
                            for (int i = 1; i <= pages; i++)
                            {
                                ColumnText.ShowTextAligned(stamper.GetUnderContent(i), Element.ALIGN_LEFT, new Phrase("Page | " + (i) + "/" + pages, footerFont), 20f, 15f, 0);
                            }
                        }
                        bytes = stream.ToArray();
                    }
                    fileName = "U65_CertificatePDF" + System.DateTime.Now.Ticks + ".pdf";
                    response = new FileContentResult(bytes, "application/octet-stream");
                    response.FileDownloadName = fileName;
                    return(response);
                    // return View("U65Certificate", model); // Return Html View Don't Remove
                }
                else
                {
                    return(View("NotFound", model));
                }
            }
            else
            {
                return(View("NotFound"));
            }
        }