// public ReportResult showLetter(int idx=11) public ActionResult showLetter(ChkBook_collectorDetail collectionForm) { int idx = collectionForm.checkbookId; ReportGenerator reportGen = new ReportGenerator(); string rname = "";//userManager.getReportbyName(pgId); ViewBag.msgTitle = rname; ViewBag.Title = rname; // Customize the Text Fields ReportsMap rep = new ReportsMap(); rep.fieldId = 1; rep.field1 = ""; rep.field2 = ""; rep.field3 = ""; rep.field4 = ""; rep.field5 = ""; var reportList = new List<ReportsMap>(); reportList.Add(rep); var report = new Report(reportList.ToReportSource()); string data1 = "---", data2 = "", data3 = "", data4 = ""; //Read File string fileName = fngetSystemParamter("COLLECTION LETTER TEMPLATE"); string agent = collectionForm.FullNames; Document myDocument = new Document(PageSize.A4.Rotate()); try { string fileLocation = HttpContext.Server.MapPath(".") + @"\Letter\" + "collection.pdf"; if (!Directory.Exists(HttpContext.Server.MapPath(".") + @"\Letter\")) { Directory.CreateDirectory(HttpContext.Server.MapPath(".") + @"\Letter\"); } if (System.IO.File.Exists(fileLocation)) { System.IO.File.Delete(fileLocation); } PdfWriter.GetInstance(myDocument, new FileStream(fileLocation, FileMode.OpenOrCreate)); myDocument.Open(); Contacts contactObj = new Contacts();//"0100047012" chqBook_CheckBookFieldDec chkBkFields = db.chqBook_CheckBookFieldDecs.Single(p => p.checkbookId == idx); List<Contacts> contactsList = db.ContactsList.Where(p => p.Customer_No == chkBkFields.acc_no).ToList<Contacts>(); int i = 0; foreach (Contacts contactmodel in contactsList) { if (i == 0) { contactObj = contactmodel; } i++; } string[] lines = System.IO.File.ReadAllLines(fileName); string[] data; string printData = ""; string footerText = ""; int footerCount = 0; foreach (string lin in lines) { string tempData = lin; if (lin.Contains("<<date>>")) { tempData = DateTime.Now.ToString("MMMM") + " " + DateTime.Today.Day.ToString() + " , " + DateTime.Today.Year.ToString(); ; //lin.Replace("<<Flex_Name>>", contactObj.Customer_Name); } if (lin.Contains("<<Flex_Name>>")) { tempData = lin.Replace("<<Flex_Name>>", contactObj.Customer_Name); } if (lin.Contains("<<Address_Line_1>>")) { tempData = lin.Replace("<<Address_Line_1>>", contactObj.Address_Line1); } if (lin.Contains("<<Address_Line_2>>")) { tempData = lin.Replace("<<Address_Line_2>>", contactObj.Address_Line2); } if (lin.Contains("<<SERIES>>")) { tempData = lin.Replace("<<SERIES>>", collectionForm.Series); } if (tempData.Contains("<<NO_OF_BOOKS>>")) { tempData = tempData.Replace("<<NO_OF_BOOKS>>", collectionForm.no_of_books); } if (lin.Contains("<<Account_No>>")) { tempData = lin.Replace("<<Account_No>>", chkBkFields.acc_no); } if (lin.Contains("<<AGENT>>")) { tempData = lin.Replace("<<AGENT>>", agent); } if (tempData.Contains("<<ISSUED>>")) { tempData = tempData.Replace("<<ISSUED>>", System.DateTime.Now.ToString("dd-MMM-yyyy")); } if (tempData.Contains("Citibank, N.A.")) { footerCount = 1; } if (footerCount == 0) { printData = printData + tempData + "\n"; } else { footerText = footerText + tempData + "\n"; } } // } report.TextFields.Header = printData; report.TextFields.Footer = footerText; myDocument.Add(new Paragraph(printData)); myDocument.Add(new Paragraph(footerText)); //myDocument.Close(); report.RenderHints.BooleanCheckboxes = true; report.RenderHints.BooleansAsYesNo = true; report.RenderHints.FreezeRows = 9; report.RenderHints.FreezeColumns = 2; // Customize the data fields report.DataFields["fieldId"].Hidden = true; // report.DataFields["field1"].Hidden = true; report.DataFields["field1"].HeaderText = " ";// .DataFormatString="{0:c}"; report.DataFields["field2"].Hidden = true; report.DataFields["field3"].Hidden = true; report.DataFields["field4"].Hidden = true; report.DataFields["field5"].Hidden = true; report.DataFields["field6"].Hidden = true; } catch (DocumentException de) { Console.Error.WriteLine(de.Message); } finally { myDocument.Close(); } // // Return the ReportResult // // the type of report that is rendered will be determined by the extension in the URL (.pdf, .xls, .html, etc) //return new ReportResult(); return RedirectToAction("CollectionLetterpdf"); }