Ejemplo n.º 1
0
        /// <summary>第三種透過 PartialView 產生PDF</summary>
        /// <returns></returns>
        public ActionResult DownloadPartialViewPDF()
        {
            GeneratePDFModel model = new GeneratePDFModel();


            string content = "<h2>PDF Created<h2>" +
                             "<p>透過partialView產生<p>";
            string logoFilePath = @"/Images/DotBlogsLogo.gif";

            model.PDFContent = content;
            model.PDFLogo    = Server.MapPath(logoFilePath);
            /*透過PartialView 產生PDF*/
            PartialViewAsPdf PdfPartial = new PartialViewAsPdf();

            //指定PDF內容
            PdfPartial.Model = model;
            //指定檔名
            PdfPartial.FileName = "partialViewAsPdf.pdf";
            //指定對應的partialView~_PartialViewTest.cshtml
            PdfPartial.ViewName = "_PartialViewTest";
            //設定Margin
            PdfPartial.PageMargins = new Margins()
            {
                Top = 10, Bottom = 10, Left = 10, Right = 10
            };
            //指定大小預設為A4
            PdfPartial.PageSize = Size.A4;

            return(PdfPartial);
        }
Ejemplo n.º 2
0
        /// <summary>第一種透過 View 產生PDF</summary>
        /// <returns></returns>
        public ActionResult DownloadPDF()
        {
            /*透過View 產生PDF*/
            //透過DB或是MODEL指定PDF內容
            GeneratePDFModel model   = new GeneratePDFModel();
            string           content = "<h2>Rotativa PDF From ViewAsPdf <h2>" +
                                       "<p>Rotativa真的是太方便了!!! <p>";
            string logoFilePath = @"/Images/DotBlogsLogo.gif";

            //指定PDF內容
            model.PDFContent = content;
            //圖片位置
            model.PDFLogo = Server.MapPath(logoFilePath);


            /*產生PDF*/
            ViewAsPdf GenPDF = new ViewAsPdf();

            //指定檔案名稱
            GenPDF.FileName = "ViewPdf.pdf";
            //將GeneratePDFModel 所設定的內容置入
            GenPDF.Model = model;
            //對應View GeneratePDF.cshtml
            GenPDF.ViewName = "GeneratePDF";
            //設定Margin
            GenPDF.PageMargins = new Margins()
            {
                Top = 10, Bottom = 10, Left = 10, Right = 10
            };
            //指定大小預設為A4
            GenPDF.PageSize = Size.A4;
            return(GenPDF);
        }
Ejemplo n.º 3
0
        /// <summary>ActionGeneratePDF</summary>
        /// <returns></returns>
        public ActionResult ActionGeneratePDF()
        {
            GeneratePDFModel model = new GeneratePDFModel();

            string content = "<h2>Rotativa PDF From ActionAsPdf<h2>" +
                             "<p>透過Action產生PDF<p>";
            string logoFilePath = @"/Images/DotBlogsLogo.gif";

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

            return(View(model));
        }
Ejemplo n.º 4
0
        public ActionResult DownloadActionAsPDF()
        {
            var model = new GeneratePDFModel();

            //Code to get content
            return(new Rotativa.ActionAsPdf("GeneratePDF", model)
            {
                FileName = "TestActionAsPdf.pdf",
                CustomSwitches =
                    "--footer-center \"Name: " + "Action" + "  DOS: " +
                    DateTime.Now.Date.ToString("MM/dd/yyyy") + "  Page: [page]/[toPage]\"" +
                    " --footer-line --footer-font-size \"9\" --footer-spacing 6 --footer-font-name \"calibri light\""
            });
        }