private byte[] GeneratePdfReport(string invoiceid) { byte[] result = null; int Invoiceid = Convert.ToInt32(invoiceid); HtmlToPdf objPdfSelect = new HtmlToPdf(); var htmlurl = ""; try { htmlurl = "http://localhost:44324/PDF/Report?Invoiceid=" + Invoiceid; objPdfSelect.Options.MarginTop = 5; objPdfSelect.Options.MarginBottom = 5; objPdfSelect.Options.MarginLeft = 10; objPdfSelect.Options.MarginRight = 10; objPdfSelect.Options.ViewerPreferences.CenterWindow = true; objPdfSelect.Options.ViewerPreferences.DisplayDocTitle = true; objPdfSelect.Options.ViewerPreferences.FitWindow = true; objPdfSelect.Options.ViewerPreferences.HideMenuBar = true; objPdfSelect.Options.ViewerPreferences.HideToolbar = true; objPdfSelect.Options.ViewerPreferences.HideWindowUI = true; objPdfSelect.Options.ViewerPreferences.PageMode = PdfViewerPageMode.UseNone; objPdfSelect.Options.DisplayHeader = true; objPdfSelect.Options.DisplayFooter = true; objPdfSelect.Header.DisplayOnFirstPage = true; PDFDLController obj = new PDFDLController(); reportmodel output = new reportmodel(); output = obj.Reportpdf(Invoiceid); ViewData["Report"] = output; ViewData.Model = ViewData["Report"]; StringWriter stringWriter = new StringWriter(); ViewEngineResult viewResult = ViewEngines.Engines.FindView(ControllerContext, "Report", null); ViewContext viewContext = new ViewContext( ControllerContext, viewResult.View, new ViewDataDictionary(ViewData.Model), new TempDataDictionary(), stringWriter ); viewResult.View.Render(viewContext, stringWriter); string htmlToConvert = stringWriter.ToString(); SelectPdf.PdfDocument pdffile = objPdfSelect.ConvertHtmlString(htmlToConvert); result = pdffile.Save(); pdffile.Close(); } catch (Exception ex) { throw ex; } return(result); }
public dynamic Reportpdf(int Invoiceno) { reportmodel output = new reportmodel(); try { using (AdityamineralsEntities objDB = new AdityamineralsEntities()) { output.bp = objDB.ADM_M_BILLINGPRODUCTS.ToList(); output.bp1 = objDB.ADM_L_BILLINGPART1.Where(c => c.InvoiceNo == Invoiceno).FirstOrDefault(); output.bp2 = objDB.ADM_L_BILLINGPART2.Where(c => c.InvoiceNo == Invoiceno).ToList(); } return(output); } catch (Exception ex) { return(output); } }
public ActionResult Report(int Invoiceno) { try { if (Session["UserName"] != null) { PDFDLController obj = new PDFDLController(); reportmodel output = new reportmodel(); output = obj.Reportpdf(Invoiceno); return(View()); } else { return(RedirectToAction("Login", "Login")); } } catch (Exception ex) { return(RedirectToAction("Login", "Login")); } }