public void GeneratePdf(string invoiceNumber, Stream pdfStream)
        {
            string           name;
            GetInvoiceResult invoice = this.InvoiceService.GetInvoice(new GetInvoiceParameter(invoiceNumber)
            {
                GetInvoiceLines = true
            });
            InvoiceModel invoiceModel = this.GetInvoiceMapper.MapResult(invoice, null);
            Theme        theme        = base.UnitOfWork.GetRepository <Theme>().Get(SiteContext.Current.WebsiteDto.ThemeId);

            if (theme.ThemeSource == null)
            {
                name = (theme.IsSystemTheme ? "System" : "User");
            }
            else
            {
                name = theme.ThemeSource.Name;
            }
            string          str    = string.Format("~/frontendresources/{0}/{1}/pdfviews/invoicedetails.cshtml", name, theme.Name);
            ThemeContentDto byPath = this.ThemeContentProvider.GetByPath(str);

            if (invoiceModel.InvoiceNumber.Contains("-"))
            {
                string[] invoiceNumberArray = invoiceModel.InvoiceNumber.Split('-');
                if (invoiceNumberArray.Length > 0)
                {
                    invoiceModel.InvoiceNumber = invoiceNumberArray[0];
                }
            }
            dynamic  expando     = invoiceModel.ToJson(false).ToExpando();
            DateTime invoiceDate = invoiceModel.InvoiceDate;

            expando.InvoiceDateDisplay = invoiceDate.ToShortDateString();
            invoiceDate            = invoiceModel.DueDate;
            expando.DueDateDisplay = invoiceDate.ToShortDateString();
            decimal invoiceTotal = invoiceModel.InvoiceTotal - invoiceModel.CurrentBalance;

            expando.PaymentTotalDisplay = invoiceTotal.ToString("0.00");

            foreach (dynamic obj in (IEnumerable)expando.InvoiceLines)
            {
                obj.QtyInvoicedDisplay = obj.QtyInvoiced.ToString("0");
            }

            //Display Company logo based on website
            CustomSettings customSettings = new CustomSettings();

            expando.CompanyIdentifier = customSettings.CompanyNameIdentifier;

            PdfGeneratorHelper.GeneratePdf(this.EmailTemplateRenderer.Render(byPath.Content, expando), pdfStream);
        }