Example #1
0
        //********************************************************************************************
        //
        //********************************************************************************************
        public ActionResult PrintPDF(int id)
        {
            // read parameters from the webpage
            string url = Request.Url.Authority + Request.ApplicationPath + "/Quotes/QuoteDetailsPDF/" + id;

            // instantiate a html to pdf converter object
            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();

            // set converter options
            converter.Options.PdfPageSize        = SelectPdf.PdfPageSize.A4;
            converter.Options.PdfPageOrientation = SelectPdf.PdfPageOrientation.Portrait;
            //converter.Options.WebPageWidth = webPageWidth;
            //converter.Options.WebPageHeight = webPageHeight;

            // create a new pdf document converting an url
            SelectPdf.PdfDocument doc = converter.ConvertUrl(url);

            // save pdf document
            byte[] pdf = doc.Save();

            // close pdf document
            doc.Close();

            // return resulted pdf document
            FileResult fileResult = new FileContentResult(pdf, "application/pdf");

            fileResult.FileDownloadName = "Document.pdf";
            return(fileResult);

            //return RedirectToAction("QuoteDetails/" + id);
        }
Example #2
0
        public FileResult GenerateAdminReportPdf(string date)
        {
            var tempHtmlTemplate = AppDomain.CurrentDomain.BaseDirectory + @"Content\AdminReport.html";
            var model            = new List <ReportVM>();

            string[] startDateSplit = date.Split(',');
            DateTime?startDate      = null;
            DateTime?endDate        = null;

            if (startDateSplit.Count() >= 2)
            {
                startDate = Convert.ToDateTime(startDateSplit[0]);
                endDate   = (Convert.ToDateTime(startDateSplit[1])).AddHours(23).AddMinutes(59);
                //endDate = endDate.Value.AddHours(23).AddMinutes(59);
            }
            model = _adminService.GetReportData(startDate, endDate);

            string        str = RenderPartialToString(this, "AdminReport", model, ViewData, TempData);
            StringBuilder sb  = new StringBuilder();

            foreach (var item in model)
            {
                string htmlFormat =
                    $"<tr><td style='padding: 3px 15px; border: 1px solid #ddd; font-family:arial;'>{item.Request}</td>"
                    + $"<td style='padding: 3px 15px; border: 1px solid #ddd; font-family:arial;'>{item.EligibleProperties}</td>"
                    + $"<td style='padding: 3px 15px; border: 1px solid #ddd; font-family:arial;'>{item.InEligibleProperties}</td>"
                    + $"<td style='padding: 3px 15px; border: 1px solid #ddd; font-family:arial;'>{item.Unknown}</td>";
                sb.Append(htmlFormat);
            }
            str = str.Replace("#######", sb.ToString());
            System.IO.File.WriteAllText(tempHtmlTemplate, str);
            SelectPdf.HtmlToPdf pdfFile = new SelectPdf.HtmlToPdf();
            pdfFile.Options.MarginRight = 5;
            pdfFile.Options.MarginRight = 5;
            SelectPdf.PdfDocument document = pdfFile.ConvertUrl(tempHtmlTemplate);
            //Guid rand = Guid.NewGuid();
            //string pdf = Server.MapPath("/Content/test"+ rand+".pdf");
            byte[] pd = document.Save();
            document.Close();
            FileResult fileResult = new FileContentResult(pd, "application/pdf");

            fileResult.FileDownloadName = "Report" + DateTime.Now + ".pdf";
            return(fileResult);
        }
Example #3
0
        public FileResult GenerateProjectReportPdf()
        {
            var tempHtmlTemplate = AppDomain.CurrentDomain.BaseDirectory + @"Content\CoverSheet.html";
            var model            = new List <CoverSheetVM>();

            model = _requestService.GetCoverSheetUsers();

            string        str = RenderPartialToString(this, "ProjectReport", model, ViewData, TempData);
            StringBuilder sb  = new StringBuilder();

            foreach (var item in model)
            {
                string htmlFormat = string.Format(
                    "<tr><td style='padding: 3px 15px; border: 1px solid #ddd; font-family:arial;'>{0}</td>"
                    + "<td style='padding: 3px 15px; border: 1px solid #ddd; font-family:arial;'>{1}</td>"
                    + "<td style='padding: 3px 15px; border: 1px solid #ddd; font-family:arial;'>{2}</td>"
                    + "<td style='padding: 3px 15px; border: 1px solid #ddd; font-family:arial;'>{3}</td>"
                    + "<td style='padding: 3px 15px; border: 1px solid #ddd; font-family:arial;'>{4}</td>"
                    + "<td style='padding: 3px 15px; border: 1px solid #ddd; font-family:arial;'>{5}</td>"
                    + "<td style='padding: 3px 15px; border: 1px solid #ddd; font-family:arial;'>{6}</td>"
                    , item.ProjectLogNumber, item.Date, item.ProjectName, item.ApplicantContact.Name, item.ApplicantContact.CountyName, item.LeadLegacy, item.ProjectDescription
                    );
                sb.Append(htmlFormat);
            }
            str = str.Replace("#######", sb.ToString());
            System.IO.File.WriteAllText(tempHtmlTemplate, str);
            SelectPdf.HtmlToPdf pdfFile = new SelectPdf.HtmlToPdf();
            pdfFile.Options.MarginRight = 5;
            pdfFile.Options.MarginRight = 5;
            SelectPdf.PdfDocument document = pdfFile.ConvertUrl(tempHtmlTemplate);
            //Guid rand = Guid.NewGuid();
            //string pdf = Server.MapPath("/Content/test"+ rand+".pdf");
            byte[] pd = document.Save();
            document.Close();
            FileResult fileResult = new FileContentResult(pd, "application/pdf");

            fileResult.FileDownloadName = "Document.pdf";
            return(fileResult);
        }
Example #4
0
        //********************************************************************************************
        // Save PDF
        //********************************************************************************************
        private void SaveSuppPDF(int id)
        {
            try
            {
                var tempFilesFolder = Server.MapPath(ConfigurationManager.AppSettings["TempFilesRoot"]);
                var filename        = id + "_Quote.pdf";
                var fileloc         = tempFilesFolder + "\\";
                var fullPath        = fileloc + filename;

                SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();
                string url = Request.Url.Authority + Request.ApplicationPath + "/Quotes/QuoteDetailsSuppPDF/" + id;
                converter.Options.PdfPageSize        = SelectPdf.PdfPageSize.A4;
                converter.Options.PdfPageOrientation = SelectPdf.PdfPageOrientation.Portrait;

                SelectPdf.PdfDocument doc = converter.ConvertUrl(url);

                doc.Save(fullPath);
                doc.Close();
            }
            catch (Exception ex)
            {
                //Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            }
        }