private Stream LoadPdf(string ExportFileName = "") { stream = new MemoryStream(); try { DEST = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "test1.pdf"); if (string.IsNullOrEmpty(ExportFileName)) { if (Directory.Exists(ExportFileName) == true) { DEST = ExportFileName; } } FileInfo file = new FileInfo(DEST); string jsonParam = ""; IDictionary <string, object> dictParam = new Dictionary <string, object>(); if (inoicePrinting.InputParameters == null) { if (string.IsNullOrEmpty(inv.Document.QueryParameter) == false) { string paramString = inv.Document.QueryParameter; jsonParam = OpenParameter_Dialog(paramString); var jobjParam = JsonConvert.DeserializeObject <JObject>(jsonParam); dictParam = jobjParam.ToObject <Dictionary <string, object> >(); inoicePrinting.InputParameters = dictParam; } } PrepareSqlReportData(inoicePrinting, inv, dictParam); //if (string.IsNullOrEmpty(inv.Document.DetailSource)) //{ // if (inoicePrinting.DetailData == null || inoicePrinting.DetailData.Count() == 0) // { // } //} using (MemoryStream memoryStream = new MemoryStream()) { inoicePrinting.PrintInvoice(inv, DEST, memoryStream); stream = new MemoryStream(memoryStream.ToArray()); //pdfDocumentViewer1.LoadFromStream(stream); //pdfDocumentViewer1.LoadFromFile(DEST); } browser.Navigate("about:blank"); return(stream); } catch (Exception ex) { MessageBox.Show(ex.Message); return(stream); } }
public FunctionResponse OpenPdfReport(PdfReportParameter reportParameter) { var filename = reportParameter.filename; if (string.IsNullOrEmpty(filename)) { return new FunctionResponse { status = "error", result = "Invalid file Name" } } ; var reportDirectory = _env.WebRootPath; if (filename.EndsWith(".ims") == false) { filename = filename + ".ims"; } var reportFile = Path.Combine(reportDirectory, "IMSReport", filename); if (File.Exists(reportFile) == false) { return new FunctionResponse { status = "error", result = "File not found" } } ; string str = File.ReadAllText(reportFile); inoicePrinting = new InvoicePrinting(); inv = inoicePrinting.LoadInvFromJsonString(str); if (inv.Document.DetailDataType == DataType.SQLServer) { if (!string.IsNullOrEmpty(inv.Document.QueryParameter)) { FunctionResponse res = CompareParameter(reportParameter.Parameter, inv.Document.QueryParameter); if (res.status == "error") { return(res); } inoicePrinting.InputParameters = res.result as Dictionary <string, object>; PrepareSqlReportData(inoicePrinting, inv, inoicePrinting.InputParameters); } } //var pdfFile = reportDirectory using (MemoryStream memStream = new MemoryStream()) { byte[] bytes = inoicePrinting.PrintInvoice(inv, "", memStream: memStream); return(new FunctionResponse { status = "ok", result = bytes }); } }
public FunctionResponse OpenPdfReportMultipleParameter(PdfReportMultiParameter pdfReportMultiParameter) { var filename = pdfReportMultiParameter.filename; if (string.IsNullOrEmpty(filename)) { return new FunctionResponse { status = "error", result = "Invalid file Name" } } ; var reportDirectory = _env.WebRootPath; var reportFile = Path.Combine(reportDirectory, "IMSReport", filename); if (File.Exists(reportFile) == false) { return new FunctionResponse { status = "error", result = "File not found" } } ; string str = File.ReadAllText(reportFile); inoicePrinting = new InvoicePrinting(); inv = inoicePrinting.LoadInvFromJsonString(str); List <byte[]> pdfFiles = new List <byte[]>(); foreach (var parameter in pdfReportMultiParameter.Parameters) { if (inv.Document.DetailDataType == DataType.SQLServer) { if (!string.IsNullOrEmpty(inv.Document.QueryParameter)) { FunctionResponse res = CompareParameter(parameter, inv.Document.QueryParameter); if (res.status == "error") { return(res); } inoicePrinting.InputParameters = res.result as Dictionary <string, object>; if (!(pdfReportMultiParameter.IsSameDataQuery == true && inoicePrinting.DetailData != null)) { PrepareSqlReportData(inoicePrinting, inv, inoicePrinting.InputParameters); } } using (MemoryStream memStream = new MemoryStream()) { byte[] bytes = inoicePrinting.PrintInvoice(inv, "", memStream: memStream); pdfFiles.Add(bytes); //return new FunctionResponse { status = "ok", result = memStream.ToArray() }; } } } //var pdfFile = reportDirectory using (MemoryStream memoryStream = new MemoryStream()) { inoicePrinting.MergePdfinMemory(memoryStream, pdfFiles); return(new FunctionResponse { status = "ok", result = memoryStream.ToArray() }); } }