Ejemplo n.º 1
0
        /// <summary>
        /// Action Method using viewAsPdf class to create view as pdf
        /// </summary>
        /// <returns></returns>
        public ActionResult DownloadPdf()
        {
            try
            {
                var model = new GeneratePDFModel();

                //get the information to display in pdf from database
                //for the time
                //Hard coding values are here, these are the content to display in pdf
                var content = "<h2>WOW Rotativa<h2>" +
                 "<p>Ohh This is very easy to generate pdf using Rotativa <p>";
                var logoFile = @"/Images/logo.png";

                model.PDFContent = content;
                model.PDFLogo = Server.MapPath(logoFile);

                string footer = "--footer-right \"Date: [date] [time]\" " + "--footer-center \"Page: [page] of [toPage]\" --footer-line --footer-font-size \"9\" --footer-spacing 5 --footer-font-name \"calibri light\"";

                //Use ViewAsPdf Class to generate pdf using GeneratePDF.cshtml view
                return new Rotativa.ViewAsPdf("GeneratePDF", model)
                {
                    FileName = "firstPdf.pdf",
                    CustomSwitches = footer,
                    CustomHeaders = new Dictionary<string, string> { { "Test", "Title" } }

                };
            }
            catch
            {

                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// using partial view for pdf generation
        /// </summary>
        /// <returns></returns>
        public ActionResult DownloadPartialViewPDF()
        {
            var model = new GeneratePDFModel();

            //hard coded value for test purpose
            var content = "<h2>PDF Created<h2>" +
            "<p>Ohh This is very easy to generate pdf using Rotativa<p>";
            var logoFile = @"/Images/logo.png";

            model.PDFContent = content;
            model.PDFLogo = Server.MapPath(logoFile);

            return new Rotativa.PartialViewAsPdf("_PartialViewTest", model) { FileName = "partialViewAsPdf.pdf" };
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Action method to return view as pdf
        /// </summary>
        /// <returns></returns>
        public ActionResult GeneratePDF(string name = "there")
        {
            try
            {
                var model = new GeneratePDFModel();
                //Your data from db

                //hard coded value for test purpose
                var content = "<h2>PDF Created<h2>" +
                "<p>Ohh This is very easy to generate pdf using Rotativa<p>";
                var logoFile = @"/Images/logo.png";

                model.PDFContent = content;
                model.PDFLogo = Server.MapPath(logoFile);
                model.Name = name;

                return View(model);
            }
            catch
            {
                throw;
            }
        }