Exemple #1
0
        /// <summary>
        /// HTML合同模板转PDF
        /// </summary>
        /// <param name="WebRootPath"></param>
        /// <param name="help"></param>
        /// <returns></returns>
        public static byte[] HTMLToPDF(String WebRootPath, ContractHelp help)
        {
            String       TemplatePath = WebRootPath + @"/Template/Template.html";
            StreamReader reader       = new StreamReader(TemplatePath, Encoding.UTF8);
            String       HTMLContent  = reader.ReadToEnd();
            String       PayModel     = String.Empty;

            if (help.PayModel == 10)
            {
                PayModel = "支付宝";
            }
            else if (help.PayModel == 20)
            {
                PayModel = "微信";
            }
            else if (help.PayModel == 30)
            {
                PayModel = "银行转账";
            }
            else if (help.PayModel == 40)
            {
                PayModel = "自定义支付-标签购买";
            }
            HTMLContent = HTMLContent.Replace("{CompanyCategory}", help.CompanyName)
                          .Replace("{PathNo}", help.PathNo)
                          .Replace("{CompanyName}", help.CompanyName)
                          .Replace("{CompanyCode}", help.CommunityCode)
                          .Replace("{CompanyAddress}", help.CompanyAddress)
                          .Replace("{StartTimeYear}", help.StarYear.ToString())
                          .Replace("{StartTimeMonth}", help.StarMonth.ToString())
                          .Replace("{StartTimeDay}", help.StarDay.ToString())
                          .Replace("{EndTimeYear}", help.EndYear.ToString())
                          .Replace("{EndTimeMonth}", help.EndMonth.ToString())
                          .Replace("{EndTimeDay}", help.EndDay.ToString())
                          .Replace("{Years}", help.ContractYear.ToString())
                          .Replace("{CompanyVersion}", help.VersionName)
                          .Replace("{Moneys}", Money(help).ToString())
                          .Replace("{MeneyUp}", XExten.XPlus.XPlusEx.XConvertCHN(Money(help)))
                          .Replace("{ServerItems}", help.VersionDes)
                          .Replace("{PayModel}", PayModel);
            HtmlToPdf converter = new HtmlToPdf();

            converter.Options.PdfPageSize        = PdfPageSize.A4;
            converter.Options.PdfStandard        = PdfStandard.Full;
            converter.Options.PdfPageOrientation = PdfPageOrientation.Portrait;
            converter.Options.WebPageWidth       = 1024;
            converter.Options.WebPageHeight      = 0;
            converter.Options.EmbedFonts         = true;
            converter.Options.MarginLeft         = 60;
            converter.Options.MarginRight        = 60;
            converter.Options.MarginTop          = 60;
            converter.Options.MarginBottom       = 60;

            SelectPdf.PdfDocument doc = converter.ConvertHtmlString(HTMLContent);
            byte[] bytes = doc.Save();
            doc.Close();
            return(bytes);
        }
Exemple #2
0
        public FileResult HTMLToPDF(ContractHelp help)
        {
            var WebRootPath = Environment.WebRootPath;

            byte[]     bytes = FileUtil.HTMLToPDF(WebRootPath, help);
            FileResult PDF   = new FileContentResult(bytes, "application/pdf");

            PDF.FileDownloadName = "入住合同.pdf";
            return(PDF);
        }
Exemple #3
0
 /// <summary>
 /// 计算版本价格
 /// </summary>
 /// <param name="help"></param>
 /// <returns></returns>
 public static int Money(ContractHelp help)
 {
     try
     {
         var price = help.AttachInfo.Replace("元", "").Trim();
         return(Convert.ToInt32(price) * help.ContractYear);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }