public static string GetHTMLString(CalculatedPriceModel calculatedPriceModel) { var sb = new StringBuilder(); sb.Append(@" <html> <head> </head> <body> <div class='header'><h1>This is the generated PDF report of the gold price estimation</h1></div> <table align='center'> <tr> <th>Gold Price (per gram)</th> <th>Weight (grams)</th> <th>Discount %</th> <th>Total price</th> </tr>"); sb.AppendFormat(@"<tr> <td>{0}</td> <td>{1}</td> <td>{2}</td> <td>{3}</td> </tr>", calculatedPriceModel.GoldPrice, calculatedPriceModel.Weight, calculatedPriceModel.Discount != null ? calculatedPriceModel.Discount.Value + " %" : "-", calculatedPriceModel.TotalPrice); sb.Append(@" </table> </body> </html>"); return(sb.ToString()); }
public void Print(CalculatedPriceModel priceModel) { string fileStoragePath = _configuration.GetValue <string>(Constants.FileStoragePath); if (string.IsNullOrWhiteSpace(fileStoragePath)) { throw new Exception(string.Format(ErrorMessageConstants.InvalidConfigurationKey, Constants.FileStoragePath)); } var context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll")); var _converter = new SynchronizedConverter(new PdfTools()); if (!Directory.Exists(fileStoragePath)) { Directory.CreateDirectory(fileStoragePath); } var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, DocumentTitle = "PDF Report", Out = Path.Combine(fileStoragePath, "GoldPriceEstimation" + "_" + DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss_fffff") + ".pdf") }; var objectSettings = new ObjectSettings { PagesCount = true, HtmlContent = HelperClass.GetHTMLString(priceModel), WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") }, HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true }, FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" } }; var pdf = new HtmlToPdfDocument() { GlobalSettings = globalSettings, Objects = { objectSettings } }; _converter.Convert(pdf); }
private CalculatedPriceModel GetCalculatedPriceModel(PriceEstimationModel priceEstimationModel, decimal totalPrice) { CalculatedPriceModel calculatedPriceModel = null; if (priceEstimationModel != null) { calculatedPriceModel = new CalculatedPriceModel { GoldPrice = priceEstimationModel.GoldPrice, Weight = priceEstimationModel.Weight, Discount = eligibleForDiscount ? priceEstimationModel.Discount : null, TotalPrice = totalPrice }; } return(calculatedPriceModel); }
public void Print(CalculatedPriceModel priceModel) { throw new NotImplementedException(); }