public FileResult PDF(string html) { var host = this.HttpContext.Request.Scheme + "://" + this.HttpContext.Request.Host.Value; var matches = Regex.Matches(html, @"href=""(\/.*)"">"); foreach (Match match in matches) { var value = match.Groups[1].Value; html = html.Replace(value, host + value); } var wkhtmltopdf = new FileInfo(@"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"); var converter = new HtmlToPdfConverter(wkhtmltopdf); var settings = new ConversionSettings( pageSize: PageSize.A4, orientation: PageOrientation.Portrait, margins: new PageMargins(10, 5, 5, 5), grayscale: false, lowQuality: false, quiet: true, enableJavaScript: true, javaScriptDelay: null, enableExternalLinks: true, enableImages: true, executionTimeout: null); var pdfBytes = converter.ConvertToPdf(html, Encoding.UTF8, settings); string result = System.Text.Encoding.UTF8.GetString(pdfBytes); return(File(pdfBytes, "application/pdf", "magic.pdf")); }
public IActionResult Index(string html) { var converter = new HtmlToPdfConverter(HtmlToPdfBinary); var pdfBytes = converter.ConvertToPdf(html); return(File(pdfBytes, "application/pdf", "export.pdf")); }
public static void Setup(IConfiguration configuration) { // Note: This could also been done on the constructor of the Controller // Here, we can do it only once. // 1. Check configuration var path = configuration["PdfConverter"]; if (string.IsNullOrEmpty(path)) { throw new ApplicationException("Error: Please define 'PdfConverter' in app settings."); } // 2. Check binary PdfyController.HtmlToPdfBinary = new FileInfo(path); if (!PdfyController.HtmlToPdfBinary.Exists) { throw new ApplicationException("Error: The PDF Converter binary does not exist in the path: " + path); } // 3. Check if the converter works var converter = new HtmlToPdfConverter(PdfyController.HtmlToPdfBinary); var pdfBytes = converter.ConvertToPdf("Hello there, convert me."); if (pdfBytes == null) { throw new ApplicationException("Error: The PDF Converter is not working correctly. Please check."); } // 4. All pass: Console.WriteLine("All checks passed. Starting PDFy Server. 👍"); }
public async Task <IActionResult> DownloadPdf() { var htmlContent = await _viewRenderService.RenderToStringAsync("Home/About", new object()); var wkhtmltopdf = new FileInfo(@"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"); var converter = new HtmlToPdfConverter(wkhtmltopdf); var pdfBytes = converter.ConvertToPdf(htmlContent); FileResult fileResult = new FileContentResult(pdfBytes, "application/pdf"); fileResult.FileDownloadName = "test.pdf"; return(fileResult); }
public IActionResult Index([FromBody] PayloadModel model) { if (!ModelState.IsValid) { return(new BadRequestObjectResult(new { Error = "The model is not formatted properly. " + "Please set headers as application/json and provide proper model." })); } var converter = new HtmlToPdfConverter(HtmlToPdfBinary); var pdfBytes = converter.ConvertToPdf(model.html); return(File(pdfBytes, "application/pdf", "export.pdf")); }
public async Task <IActionResult> DownloadPdf(string id) { var title = _context.Posts.FirstOrDefault(a => a.Id == id); var model = _context.Posts.Include(a => a.Author).Where(a => a.ParentId == id).ToList(); var htmlContent = await _viewRenderService.RenderToStringAsync("Posts/Pdf", model); var wkhtmltopdf = new FileInfo(@"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"); var converter = new HtmlToPdfConverter(wkhtmltopdf); var pdfBytes = converter.ConvertToPdf(htmlContent); FileResult fileResult = new FileContentResult(pdfBytes, "application/pdf") { FileDownloadName = title.Title }; return(fileResult); }
public IActionResult CreatePDF(int id) { //Variables string invoiceNumber = ""; string logo = Path.Combine(_env.WebRootPath, "images/" + _settings.Logo); //Instances Invoice invoice = null; Debtor debtor = null; Company company = null; List <InvoiceItem> invoiceItems = null; List <Product> productList = new List <Product>(); try { invoice = _context.Invoices.SingleOrDefault(s => s.InvoiceNumber == id); debtor = _context.Debtors.SingleOrDefault(s => s.DebtorID == invoice.DebtorID); invoiceItems = _context.InvoiceItems.Where(s => s.InvoiceNumber == invoice.InvoiceNumber).ToList(); if (debtor == null) { int cid = (int)invoice.CompanyID; company = _context.Companies.SingleOrDefault(s => s.CompanyID == cid); } } catch (Exception ex) { Debug.WriteLine(ex); } foreach (var item in invoiceItems) { Product product = _context.Products.Single(s => s.ProductID == item.ProductID); productList.Add(product); } if (_settings.Prefix != "") { invoiceNumber = _settings.Prefix + "-" + invoice.InvoiceNumber.ToString(); } else { invoiceNumber = invoice.InvoiceNumber.ToString(); } //CSS string var cssString = @"<style> .invoice-box { max-width: 2480px; max-height: 3495px: width: 100%; height: 90%; margin: auto 0; padding: 30px 7px; font-size: 15px; line-height: 24px; font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; color: #555; letter-spacing: 0px; } .invoice-box table { width: 100%; line-height: inherit; text-align: left; } .invoice-box table td { padding: 5px 0px; vertical-align: top; } .invoice-box table tr.top table td { padding-bottom: 50px; } .invoice-box table .top td .title { font-size: 32px; line-height: 32px; padding-left: 65px !important; color: #333; float: left; width: 80%; text-align: left; } .invoice-box table .top td .logo { padding-left: 0px !important; float: left; max-width: 65%; height: auto; text-align: left; } .invoice-box table .top .company { float: right; font-size: 13.5px; text-align: left !important; width: 30%; align: right !important; margin-right: 0; padding-right: 10px; margin-left: 10px; } .invoice-box table .top .company hr{ margin-left: auto; margin-right: auto; width: 100%; height: 2px; margin-top: 2px; margin-bottom: 0; padding-bottom: 1px; } .invoice-box .debtor-table{ margin-left: 55px !important; margin-bottom: 45px !important; } .invoice-box .debtor-table .debtor-info{ border-collapse: collapse; border-spacing; 0; padding: 0 0 0 0; margin: 0 0 0 15px; } .invoice-box .debtor-table .debtor-info tr{ padding: 0 0 0 0; margin: 0 0 0 0; } .invoice-box .debtor-table .debtor-name, .invoice-box .debtor-table .debtor-address, .invoice-box .debtor-table .debtor-city{ font-size: 16px; text-align: left !important; padding-bottom: 0px; line-height: normal; } .invoice-box .invoice-info{ border-collapse: collapse; border-spacing; 0; padding: 0 0 0 0; margin: 8px 0 65px 55px !important; width: 30%; } .invoice-box .invoice-info tr{ margin: 0 0 0 0 !important; padding: 0 0 0 0; line-height: 64%; font-size: 16px; border-collapse: collapse; border-spacing; 0; } .invoice-box .invoice-info tr td:nth-child(1){ width: 40%; } .invoice-box .invoice-info tr td:nth-child(2){ width: 60% padding-left: 2px; text-align: left; align: left; } .invoice-box .item-table tr.heading td { background: #eee; border-bottom: 1px solid #ddd; font-weight: bold; font-size: 15px; } .invoice-box .item-table tr.details td { padding-bottom: 20px; } .invoice-box .item-table{ margin-bottom: 25px !important; } .invoice-box .item-table tr.item td { border-bottom: 1px solid #eee; font-size: 14px; } .invoice-box .item-table tr.item.last td { border-bottom: none; } .invoice-box .item-table tr td:nth-child(1){ border-top: 2px solid #eee; width: 26%; padding-left: 4px; } .invoice-box .item-table tr td:nth-child(2){ width: 34%; } .invoice-box .item-table tr td:nth-child(4), .invoice-box .item-table tr td:nth-child(5), .invoice-box .item-table tr td:nth-child(6){ text-align: center; } .invoice-box .item-table tr td:nth-child(3){ width: 12%; text-align: center; } .invoice-box .item-table tr td:nth-child(4), .invoice-box .item-table tr td:nth-child(5){ width: 8%; } .invoice-box .item-table tr td:nth-child(6){ width: 12% } .invoice-box .total-table{ border-collapse: collapse; border-spacing; 0; width: 18%; float: right; margin: 5px 35px 0 0 !important; padding: 0 0 0 0 !important; } .invoice-box .total-table .total{ border-top: 1px solid #888; } .invoice-box .total-table tr td:nth-child(1){ font-weight: 600; text-align: right; font-size: 15px; padding-bottom: 1px; width: 40%; } .invoice-box .total-table tr td:nth-child(2){ font-weight: 800; text-align: left; font-size: 15px; padding-bottom: 1px; padding-left: 6px; width: 60%; } .invoice-box .disclaimer-table{ width: 100%; border-top: 2px solid #DDD; margin: 0 0 0 0 !important; padding: 0 0 0 0 !important; position: fixed !important; bottom: 4%; left: 0%; } .invoice-box .disclaimer-table .message .message-text{ font-size: 16px; text-align: center; padding: 5px 25px !important; } @media only screen and (max-width: 600px) { .invoice-box table tr.top table td { width: 100%; display: block; text-align: center; } .invoice-box table tr.information table td { width: 100%; display: block; text-align: center; } } </style>"; //Company string string companyString = @"<div class=invoice-box> <table cellpadding=0 cellspacing=0> <tr class=top> <td colspan=2> <table> <tr> <td class=title>"; if (_settings.UseLogoInPDF == true) { companyString += "<img class=logo src=" + logo + " />"; } else { companyString += "<h2>" + _settings.CompanyName + "</h2>"; } companyString += "</td>" + "<td class=company>" + "<b>" + _settings.CompanyName + "</b>" + "<hr />" + _settings.Address + "<br />" + _settings.PostalCode + " " + _settings.City + "<br />" + _settings.Country + "<hr />" + "<b>Tel: </b>" + _settings.Phone + "<br />" + "<b>Web: </b>" + _settings.Website + "<hr />" + "<b>Reg No: </b>" + _settings.RegNumber + "<br />" + "<b>VAT: </b>" + _settings.FinancialNumber + "</td>" + "</tr> " + "</table> " + "</td>" + "</tr>" + "</table>"; string debtorString = ""; //Debtor string if (debtor != null) { debtorString = @"<table class=debtor-table cellpadding=0 cellspacing=0>" + "<tr>" + "<td class=debtor-name>" + debtor.FirstName + " " + debtor.LastName + "</td>" + "</tr>" + "<tr>" + "<td class=debtor-address>" + debtor.Address + "</td>" + "</tr>" + "<tr>" + "<td class=debtor-city>" + debtor.PostalCode + " " + debtor.City + "</td>" + "</tr>" + "</table>"; } else if (company != null) { debtorString = @"<table class=debtor-table cellpadding=0 cellspacing=0>" + "<tr>" + "<td class=debtor-name>" + company.CompanyName + "</td>" + "</tr>" + "<tr>" + "<td class=debtor-address>" + company.Address + "</td>" + "</tr>" + "<tr>" + "<td class=debtor-city>" + company.PostalCode + " " + company.City + "</td>" + "</tr>" + "</table>"; } //Spacer string string spacerString = @"<br />"; //Invoice info string invoiceString = @"<table class=invoice-info cellpadding=0 cellspacing=0>" + "<tr>" + "<td><b>Date: </b></td>" + "<td>" + invoice.CreatedOn.ToString("dd-MM-yyyy") + "</td>" + "</tr>" + "<tr>" + "<td><b>Invoice No: </b></td>" + "<td>" + invoiceNumber + "</td>" + "</tr>" + "</table>"; //Product string string productString = @"<table class=item-table cellpadding=0 cellspacing=0>" + "<tr class=heading> " + "<td>Product</td>" + "<td>Description</td>" + "<td>Price</td>" + "<td>Qnt</td>" + "<td>VAT</td>" + "<td>Total</td>" + "</tr>"; //Table string string tableString = ""; decimal totalBeforeDiscount = 0; decimal totalAmount = invoice.Total; decimal subTotalAmount = 0; decimal vatTotalAmount = 0; decimal discount = 0; int discountPercentage = invoice.Discount; for (int i = 0; i < invoiceItems.Count; i++) { InvoiceItem item = invoiceItems[i]; Product product = productList.Single(s => s.ProductID == item.ProductID); int vatPercentage = 100 + product.VAT; decimal total = (decimal)(product.Price * item.Amount); decimal subTotal = (decimal)(product.Price * 100) / vatPercentage; totalBeforeDiscount += total; subTotalAmount += subTotal; tableString += @"<tr class=item>" + "<td>" + product.Name + "</td>" + "<td>" + product.Description + "</td>" + "<td>€ " + String.Format("{0:N2}", product.Price) + "</td>" + "<td>" + item.Amount + "</td>" + "<td>" + String.Format("{0}%", product.VAT) + "</td>" + "<td>€ " + String.Format("{0:N2}", total) + "</td>" + "</tr>"; } vatTotalAmount = totalAmount - subTotalAmount; discount = (totalBeforeDiscount * discountPercentage) / 100; Debug.WriteLine("Discount Percentage: " + discountPercentage + "%"); Debug.WriteLine("Discount: " + discount); tableString += "</table>"; //Total string string totalString = @"<table class=total-table cellspacing=0 cellpadding=0>" + "<tr class=vat>" + "<td>VAT:</td>" + "<td>€ " + String.Format("{0:N2}", vatTotalAmount) + "</td>" + "</tr>" + "<tr class=subtotal>" + "<td>Subtotal:</td>" + "<td>€ " + String.Format("{0:N2}", subTotalAmount) + "</td>" + "</tr>" + "<tr class=discount>" + "<td>Discount:</td>" + "<td>€ " + String.Format("{0:N2}", discount) + "</td>" + "</tr>" + "<tr class=total>" + "<td>Total:</td>" + "<td>€ " + String.Format("{0:N2}", totalAmount) + "</td>" + "</tr>" + "</table>"; //Disclaimer string string disclaimerString = @"<table class=disclaimer-table cellspacing=0 cellpadding=0>" + "<tr class=message>" + "<td><p class=message-text> We kindly request you to pay the amount of <b>" + String.Format("€{0:N2}", totalAmount) + "</b> described above before <b>" + invoice.ExpirationDate.ToString("dd-MM-yyyy") + "</b> on our bank account <b>" + _settings.BankAccountNumber + "</b> in the name of <b>" + _settings.CompanyName + "</b>, indicating the invoice number <b>" + invoiceNumber + "</b>. For questions, please contact." + "</p></td>" + "</tr>" + "</table>" + "</div>"; //Full HTML string string htmlContent = cssString + companyString + debtorString + spacerString + invoiceString + productString + tableString + totalString + disclaimerString; var wkhtmltopdf = new FileInfo(@"wkhtmltopdf\bin\wkhtmltopdf.exe"); var converter = new HtmlToPdfConverter(wkhtmltopdf); var pdfBytes = converter.ConvertToPdf(htmlContent); FileResult fileResult = new FileContentResult(pdfBytes, "application/pdf"); fileResult.FileDownloadName = "invoice-" + id + ".pdf"; return(fileResult); }
public IActionResult DownloadPdf(AccountStatementViewModel model) { var sbuilder = new StringBuilder(); var beginningOfPage = @"<html xmlns='http://www.w3.org/1999/xhtml'><head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <meta name='viewport' content='width=device-width, initial-scale=1.0'> <title>Account Statement</title> <style type='text/css'> /* Client-specific Styles */ #outlook a{padding: 0;}/* Force Outlook to provide a 'view in browser' menu link. */ body{width: 100% !important; -webkit-text-size-adjust: 100%; background: #F8F8F8; -ms-text-size-adjust: 100%; margin: 0; padding: 0; color: #333333; font-family: Helvetica, Arial, sans-serif;}/* Prevent Webkit and Windows Mobile platforms from changing default font sizes, while not breaking desktop design. */ .ExternalClass{width: 100%;}/* Force Hotmail to display emails at full width */ .ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div{line-height: 100%;}/* Force Hotmail to display normal line spacing. */ #backgroundTable{margin: 0; padding: 0; width: 100% !important; line-height: 100% !important;}img{outline: none; text-decoration: none; border: none; -ms-interpolation-mode: bicubic;}a{color: #7a023f;}strong{font-weight: 700 !important;}b{font-weight: 700 !important;}tr{vertical-align: top !important;}a img{border: none;}.image_fix{display: block;}/*p{margin: 0px 0px !important;}*/ /* fixes */ .norm{font-size: 13px; line-height: 14px;}.sideHeadings{font-weight: bold; text-align: left; padding: 6px 8px 6px 0 !important; font-size: 13px; Color: #999999;}.roomDuration{color: #333333; font-weight: bold; text-align: left; padding: 6px 8px 6px 0 !important;}.sect td, .sumSect td, .lastSect td, .paySect td{padding: 6px; vertical-align: top !important; line-height: 19px;}.paySect{border-bottom: 1px solid #DDDDDD;}.last{border-color: #000000;}.infoSect{line-height: 19px;}.sectTitleBg{text-transform: uppercase !important; font-size: 12px !important; font-weight: bold !important; color: #FFFFFF !important; background: #000040; text-align: left !important; line-height: 20px !important; padding: 8px 14px !important; display: block !important;}.littleRight{font-size: 10px; color: #999999; text-align: right;}.price{text-align: right; padding: 5px}.vat{color: #999; font-size: 10px; line-height: 10px;}.infoArea{font-size: 13px; line-height: 18px; width: 520px;}.undoreset table{table-layout: fixed !important; margin: 0 auto !important;}.uberlink{color: #1FBAD6 !important; text-decoration: none;}table td{border-collapse: collapse;}table{border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; vertical-align: top; table-layout: fixed;}table table{table-layout: auto;}/*a{color: #e95353;text-decoration: none;text-decoration:none!important;}*/ /*STYLES*/ table[class=full]{width: 100%; clear: both;}</style></head><body>"; var printhtml1 = @"<table width='100%' border='0' cellspacing='0' cellpadding='0' style='' bgcolor='#F8F8F8'> <tr> <td align='center'> <table width='100%' border='0' align='center' cellpadding='0' cellspacing='0' class='deviceWidth'> <tr> <td width='600' align='center'>"; var printhtml2 = @"<div class='block'> <table width='100%' bgcolor='#F8F8F8' cellpadding='0' cellspacing='0' border='0' id='backgroundTable'> <tbody> <tr> <td> <table width='100%' bgcolor='#FFF' cellpadding='0' cellspacing='0' border='0' align='center' class='devicewidth'> <tbody> <tr> <td align='center'> <table cellpadding='0' cellspacing='0' border='0' align='center' class='devicewidth' width='96%'> <tbody> <tr> <td valign='middle' align='right' style='padding: 25px 0 15px 15px;' class='logo'> <div class='imgpop'> <a href='' title='ARM Investment Managers Account Statement' alt='ARM Investment Managers Account Statement'><img src='~/img/logo.png' alt='ARM' border='0' style='display:block; border:none; outline:none; text-decoration:none; max-width:150px;' class='logo'></a> </div></td></tr></tbody> </table> </td></tr></tbody> </table> </td></tr></tbody> </table> </div>"; //customer details var acctCustomerBegin = @"<div class='block'> <table width='100%' bgcolor='#F8F8F8' cellpadding='0' cellspacing='0' border='0' id='backgroundTable'> <tbody> <tr> <td> <table bgcolor='#ffffff' width='100%' cellpadding='0' cellspacing='0' border='0' align='center' class='devicewidth'> <tbody> <tr> <td width='100%' height='10'></td></tr><tr> <td align='center'> <table width='96%' align='center' cellpadding='0' cellspacing='0' border='0' class='devicewidthinner'> <tbody> <tr> <td colspan='2' st-title='rightimage-title' background='#DDDDDD'><div style='text-transform:uppercase !important; font-size: 20px !important; font-weight:bold !important; color: #000000 !important; background:#DDDDDD; text-align:center !important;line-height: 20px !important; padding:8px 14px !important; display:block !important;'>CLIENT STATEMENT</div></td></tr><tr> <td height='5' colspan='2'></td></tr>"; var acctCustomer = $@"<tr> <td><div style='padding:20px 0; font-size:18px; font-weight:bold;'>{model.CustomerDetails.LastName.ToUpper()} {model.CustomerDetails.FirstName}</div></td><td width='180'><div style='text-align:right; font-size:13px; padding:20px 0; display:block;'>Print Date: {model.CurrentTimeStamp}</div></td></tr><tr> <td colspan='2' style='font-size: 12px; background:#F4F4E8; text-align:left;line-height: 20px;' st-title='rightimage-title'> <table style='font-size:13px; background:#FFFFFF' width='40%'> <tr class='sect' valign='top'> <td style='font-weight:bold; text-align:left; padding:6px 8px 6px 0 !important; font-size: 13px; Color: #999999;'>Membership Number:</td><td style='padding:6px 0 6px 8px !important;'>{model.CustomerDetails.MembershipNumber}</td></tr><tr class='sect' valign='top'> <td style='font-weight:bold; text-align:left; padding:6px 8px 6px 0 !important; font-size: 13px; Color: #999999; '>Email Address:</td><td style='padding:6px 0 6px 8px !important;'>{model.CustomerDetails.EmailAddress}</td></tr><tr class='sect' valign='top'> <td style='font-weight:bold; text-align:left; padding:6px 8px 6px 0 !important; font-size: 13px; Color: #999999;'>Phone Number:</td><td style='padding:6px 0 6px 8px !important;'>{model.CustomerDetails.PhoneNumber}</td></tr></table> </td></tr>"; var acctCustomerEnd = @"<tr> <td width='100%' colspan='2' height='10'></td></tr></tbody> </table> </td></tr></tbody> </table> </td></tr></tbody> </table> </div>"; //summaries var summaryBegin = @"<div class='block'> <table width='100%' bgcolor='#FFFFFF' cellpadding='0' cellspacing='0' border='0' id='backgroundTable' st-sortable='rightimage'> <tbody> <tr> <td> <table bgcolor='#ffffff' width='100%' cellpadding='0' cellspacing='0' border='0' align='center' class='devicewidth' modulebg='edit'> <tbody> <tr> <td align='center'> <table width='96%' align='center' border='0' cellpadding='0' cellspacing='0' class='devicewidthinner'> <tbody> <tr> <td height='5'></td></tr>"; var summary = @"<tr> <td style='font-size: 12px; background:#F4F4E8; text-align:left;line-height: 20px;' st-title='rightimage-title'>"; var summary2 = String.Empty; var summary3 = String.Empty; var summary4 = String.Empty; if (model.Summaries != null && model.Summaries.Count > 0) { summary2 = @"<table style='font-size:13px; background:#FFFFFF' width='100%'> <tr class='paySect'> <td style='padding:6px; vertical-align:top !important; line-height:19px; border-bottom:1px solid #DDDDDD; font-weight: bold; font-size:15px;'>Fund</td><td style='padding:6px; vertical-align:top !important; line-height:19px; border-bottom:1px solid #DDDDDD; font-weight: bold; font-size:15px;'>Current Balance</td><td style='padding:6px; vertical-align:top !important; line-height:19px; border-bottom:1px solid #DDDDDD; font-weight: bold; font-size:15px;'>Accrued Interest</td></tr>"; foreach (var summaryInfo in model.Summaries) { summary3 = summary3 + $@"<tr class='paySect' valign='top'> <td style='padding:6px; vertical-align:top !important; line-height:19px; border-bottom:1px solid #DDDDDD;'>{summaryInfo.ProductName}</td><td style='padding:6px; vertical-align:top !important; line-height:19px; border-bottom:1px solid #DDDDDD;'>₦{summaryInfo.CurrentBalance.ToString("F2")}</td><td style='padding:6px; vertical-align:top !important; line-height:19px; border-bottom:1px solid #DDDDDD;'>₦{summaryInfo.AccruedInterest.ToString("F2")}</td></tr>"; } summary4 = "</table>"; } var summary5 = @"</td></tr>"; var summaryEnd = @"<tr> <td width='100%' height='40'></td></tr></tbody> </table> </td></tr></tbody> </table> </td></tr></tbody> </table> </div>"; //fund var fundListingStart = $@"<div class='block'> <table width='100%' bgcolor='#F8F8F8' cellpadding='0' cellspacing='0' border='0' id='backgroundTable' st-sortable='rightimage'> <tbody> <tr> <td> <table bgcolor='#ffffff' width='100%' cellpadding='0' cellspacing='0' border='0' align='center' class='devicewidth' modulebg='edit'> <tbody> <tr> <td align='center'> <table width='96%' align='center' border='0' cellpadding='0' cellspacing='0' class='devicewidthinner'> <tbody> <tr> <td st-title='rightimage-title'><div style='padding:15px 0px; border-top:1px dotted #bbb; font-size: 13px !important; text-align:left !important;'><span style='font-weight:bold; font-size:16px; line-height: 24px; color: #000000 !important;'>{model.ProductDetails.ProductName}</span></div></td></tr><tr> <td st-title='rightimage-title'><div style='padding:15px 0px; border-top:1px solid #bbb; font-size: 13px !important; text-align:left !important;'>Reporting Period: {model.Start.ToString("dd-MMM-yyyy")} to {model.End.ToString("dd-MMM-yyyy")}</div></td></tr><tr> <td height='5'></td></tr><tr> <td style='font-size: 12px; background:#F4F4E8; text-align:left;line-height: 20px;' st-title='rightimage-title'>"; var transact = String.Empty; var transact2 = String.Empty; var transact3 = String.Empty; if (model.Transactions != null && model.Transactions.Count > 0) { var closingUnit = 0; var closingPrice = 0; var closingValue = 0; transact = @"<table style='font-size:13px; background:#FFFFFF' width='100%'> <tr class='paySect'> <td style='padding:6px; vertical-align:top !important; line-height:12px; border-bottom:1px solid #DDDDDD; font-weight: bold; font-size:13px;'>Date</td><td style='padding:6px; vertical-align:top !important; line-height:12px; border-bottom:1px solid #DDDDDD; font-weight: bold; font-size:13px;'>Type</td><td style='padding:6px; vertical-align:top !important; line-height:12px; border-bottom:1px solid #DDDDDD; font-weight: bold; font-size:13px;'>Amt Invested</td><td style='padding:6px; vertical-align:top !important; line-height:12px; border-bottom:1px solid #DDDDDD; font-weight: bold; font-size:13px;'>Unit Purchased</td><td style='padding:6px; vertical-align:top !important; line-height:12px; border-bottom:1px solid #DDDDDD; font-weight: bold; font-size:13px;'>Unit Price</td><td style='padding:6px; vertical-align:top !important; line-height:12px; border-bottom:1px solid #DDDDDD; font-weight: bold; font-size:13px;'>Value</td><td style='padding:6px; vertical-align:top !important; line-height:12px; border-bottom:1px solid #DDDDDD; font-weight: bold; font-size:13px;'>Desc</td></tr>"; foreach (var transaction in model.Transactions) { closingUnit = closingUnit + (int)transaction.Units; closingPrice = closingPrice + (int)transaction.UnitPrice; closingValue = closingValue + (int)transaction.MarketValue; var last = model.Transactions.Last(); transact2 = transact2 + $@"<tr class='paySect' valign='top'> <td style='padding:6px; vertical-align:top !important; line-height:12px; border-bottom:1px solid #DDDDDD;'>{transaction.TransactionDate.ToString("d MMM y")}</td><td style='padding:6px; vertical-align:top !important; line-height:12px; border-bottom:1px solid #DDDDDD;'>{transaction.TransactionType}</td><td style='padding:6px; vertical-align:top !important; line-height:12px; border-bottom:1px solid #DDDDDD;'>{transaction.Amount.ToString("F2")}</td><td style='padding:6px; vertical-align:top !important; line-height:12px; border-bottom:1px solid #DDDDDD;'>{transaction.Units.ToString("F2")}</td><td style='padding:6px; vertical-align:top !important; line-height:12px; border-bottom:1px solid #DDDDDD;'>{transaction.UnitPrice.ToString("F2")}</td><td style='padding:6px; vertical-align:top !important; line-height:12px; border-bottom:1px solid #DDDDDD;'>{transaction.MarketValue.ToString("F2")}</td><td style='padding:6px; vertical-align:top !important; line-height:12px; border-bottom:1px solid #DDDDDD;'>{transaction.Description}</td></tr>"; } transact3 = "</table>"; } var endOfFundListing = @"</td></tr><tr> <td width='100%' height='60'></td></tr></tbody> </table> </td></tr></tbody> </table> </td></tr></tbody> </table> </div>"; //footer var printFooter1 = @"<div class='block'> <table width='100%' bgcolor='#F8F8F8' cellpadding='0' cellspacing='0' border='0' id='backgroundTable' st-sortable='rightimage'> <tbody> <tr> <td> <table bgcolor='#ffffff' width='100%' cellpadding='0' cellspacing='0' border='0' align='center' class='devicewidth' modulebg='edit'> <tbody> <tr> <td align='center'> <table width='96%' align='center' border='0' cellpadding='0' cellspacing='0' class='devicewidthinner'> <tbody> <tr> <td height='10'></td></tr><tr> <td style='font-size: 12px; background:#F4F4E8; text-align:left;line-height: 20px;' st-title='rightimage-title'> <table style='font-size:13px; background:#FFFFFF' width='100%'> <tr> <td colspan='2' style='padding:6px; vertical-align:top !important; line-height:12px; font-weight: bold; font-size:13px;'>Lagos</td><td style='padding:6px; vertical-align:top !important; line-height:12px; font-weight: bold; font-size:13px;'>Port Harcourt</td><td style='padding:6px; vertical-align:top !important; line-height:12px; font-weight: bold; font-size:13px;'>Abuja</td><td style='padding:6px; vertical-align:top !important; line-height:12px;font-weight: bold; font-size:13px;'>Onitsha</td></tr><tr valign='top'> <td style='padding:6px; vertical-align:top !important; line-height:16px;'>1, Mekunwen Road,<br>Off Oyinkan Abayomi Drive,<br>Ikoyi, Lagos</td><td style='padding:6px; vertical-align:top !important; line-height:16px;'>68C, Coker Road, Along Town<br>Planning Way Ilupeju Lagos</td><td style='padding:6px; vertical-align:top !important; line-height:16px;'>12, Circular Road, Presidential<br>Estate By GRA Junction Port<br>Harcourt Rivers State</td><td style='padding:6px; vertical-align:top !important; line-height:16px;'>129, Adetokunbo Ademola<br>Crescent Wuse II, Abuja</td><td style='padding:6px; vertical-align:top !important; line-height:16px;'>60A Old Market Road,<br>Opposite Broad Way Cinema,<br>Onitsha, Anambra State.</td></tr></table> </td></tr><tr> <td width='100%' height='20'></td></tr></tbody> </table> </td></tr></tbody> </table> </td></tr></tbody> </table> </div>"; var printFooter2 = @"<div class='block'> <table width='100%' bgcolor='#F8F8F8' cellpadding='0' cellspacing='0' border='0' id='backgroundTable' st-sortable='fulltext'> <tbody> <tr> <td> <table bgcolor='#ffffff' width='100%' cellpadding='0' cellspacing='0' border='0' align='center' class='devicewidth' modulebg='edit'> <tbody> <tr> <td align='center'> <table width='96%' align='center' cellpadding='0' cellspacing='0' border='0' class='devicewidthinner'> <tbody> <tr> <td class='norm' style=' font-size: 13px; color: #333333; padding-right:10px; text-align:left; line-height: 18px;'><p>For enquiries: Please contact the support unit at <a href='mailto:[email protected]'>[email protected]</a> or call us on <a href='tel:07002255276'>0700CALLARM</a> (07002255276)<br><br><br></p></td></tr></tbody> </table> </td></tr></tbody> </table> </td></tr></tbody> </table> </div>"; //end of html var printendofHtml = @"</td></tr></table> </td></tr></table>"; var endOfPage = @"</body></html>"; sbuilder.Append(beginningOfPage); sbuilder.Append(printhtml1); sbuilder.Append(printhtml2); sbuilder.Append(acctCustomerBegin); sbuilder.Append(acctCustomer); sbuilder.Append(acctCustomerEnd); sbuilder.Append(summaryBegin); sbuilder.Append(summary); sbuilder.Append(summary2); sbuilder.Append(summary3); sbuilder.Append(summary4); sbuilder.Append(summary5); sbuilder.Append(summaryEnd); sbuilder.Append(fundListingStart); sbuilder.Append(transact); sbuilder.Append(transact2); sbuilder.Append(transact3); sbuilder.Append(endOfFundListing); sbuilder.Append(printFooter1); sbuilder.Append(printFooter2); sbuilder.Append(printendofHtml); sbuilder.Append(endOfPage); string html = sbuilder.ToString(); var wkhtmltopdf = new FileInfo(@"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"); var converter = new HtmlToPdfConverter(wkhtmltopdf); var settings = new ConversionSettings( pageSize: WkWrap.Core.PageSize.A4, orientation: PageOrientation.Portrait, margins: new PageMargins(10, 25, 10, 10), grayscale: true, lowQuality: true, quiet: true, enableJavaScript: true, javaScriptDelay: null, enableExternalLinks: true, enableImages: true, executionTimeout: null); var pdfBytes = converter.ConvertToPdf(html); MemoryStream workStream = new MemoryStream(); workStream.Write(pdfBytes, 0, pdfBytes.Length); workStream.Position = 0; FileStreamResult fileResult = new FileStreamResult(workStream, "application/pdf"); fileResult.FileDownloadName = "AccountStatement.pdf"; return(fileResult); }