예제 #1
0
        public FileContentResult pdf()
        {
            string html           = string.Empty;
            string uniqueId       = (string)Request.QueryString["a"];
            string page           = (string)Request.QueryString["page"];
            var    OS             = new OfficeSurveyModel();
            var    CL             = new commonLogic();
            var    htmlToPdf      = new HtmlToPdfConverter();
            var    pdfContentType = "application/pdf";

            try
            {
                OS.where     = " WHERE unique_id = '" + uniqueId + "'";
                CL.dataTable = OS.select();
                CL.pageType  = page;
                html         = CL.ViewHtml();
                string htmlContent = "<!DOCTYPE html><html lang='en'><head><style><style>body{font-family: 'Poppins', sans-serif;}.h5, h5 {font-size: 1rem; }hr{width: 100%;}hr {margin-top: 1rem;margin-bottom: 1rem;border: 0; border-top: 1px solid rgba(0, 0, 0, 0.1);}.col-md-12{width:100%;}.col-sm-8{width:60%; float:left;}.col-sm-4{width:40%;float:right;}</style></style></head><body>" + html + "</body></html>";

                //var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();
                htmlToPdf.PageFooterHtml = $@"page <span class=""page""></span> of <span class=""topage""></span>";
                var    pdfBytes = htmlToPdf.GeneratePdf(htmlContent);
                string fileName = CL.getFileName();
                return(File(pdfBytes, "application/pdf", fileName + ".pdf"));
            }
            catch (Exception e)
            {
                CL.getLog("Fail to generate PDF." + e);
                return(File(htmlToPdf.GeneratePdf("<b>Something Went wrong!!!</b>", null), pdfContentType));
            }
        }