public string GetPdfPathForWhatsApp(string UserId, string ContentID, string hdnDivContent, string ip, string hdnMarkMaxCount, string lblCaseTitle) { string directory = string.Empty; string fileName = string.Empty; StringBuilder text = new StringBuilder(hdnDivContent); #region GetContentForPDF Method Code StringBuilder UserURL = new StringBuilder(ConfigurationManager.AppSettings["APIURL"]); UserURL.Append("downloadDocument.action?"); UserURL.Append("downloadByUId="); UserURL.Append(UserId); UserURL.Append("&downloadedParentId="); UserURL.Append(ContentID); UserURL.Append("&downloadType="); UserURL.Append("free"); DO_Scrl_APILogDetailsTbl objAPILogDO = new DO_Scrl_APILogDetailsTbl(); DA_Scrl_APILogDetailsTbl objAPILogDA = new DA_Scrl_APILogDetailsTbl(); try { if (ConfigurationManager.AppSettings["ISAPIURLACCESSED"] == "1") { HttpWebRequest myRequest1 = (HttpWebRequest)WebRequest.Create(UserURL.ToString()); myRequest1.Method = "GET"; WebResponse myResponse1 = myRequest1.GetResponse(); if (ConfigurationManager.AppSettings["ISAPIResponse"] != "0") { StreamReader sr = new StreamReader(myResponse1.GetResponseStream(), System.Text.Encoding.UTF8); String result = sr.ReadToEnd(); objAPILogDO.strURL = UserURL.ToString(); objAPILogDO.intAddedBy = Convert.ToInt32(UserId); objAPILogDO.strAPIType = "Share On WhatsApp"; objAPILogDO.strResponse = result; objAPILogDO.strIPAddress = ip; objAPILogDA.AddEditDel_Scrl_APILogDetailsTbl(objAPILogDO, DA_Scrl_APILogDetailsTbl.Scrl_APILogDetailsTbl.Insert); } } //string texta = hdnDivContent.Value; text = text.Replace(""", "").Replace("<br>", "<br />").Replace("<br >", "<br />"); int countCdiv = CountStringOccurrences(text.ToString(), "</div>"); int countdiv = CountStringOccurrences(text.ToString(), "<div"); if (countCdiv == 0 && countdiv == 0) { int txtL = text.Length; text = text.Insert(txtL, "</div>"); text = text.Insert(0, "<div>"); } if (Convert.ToInt32(hdnMarkMaxCount) > 0) { for (int i = 0; i <= Convert.ToInt32(hdnMarkMaxCount); i++) { string spanOpen = "<span" + i; string replace = "<span"; string pattern = spanOpen; string result = Regex.Replace(text.ToString(), pattern, replace, RegexOptions.IgnoreCase); string spanClose = "</span" + i; replace = "</span"; pattern = spanClose; result = Regex.Replace(result.ToString(), pattern, replace, RegexOptions.IgnoreCase); text = new StringBuilder(result); } text = text.Replace("class=\"preced\"", "style=\"background-color: #ffeca0;\"").Replace("class=\"rediod\"", "style=\"background-color: #AECF00;\"").Replace("class=\"issuss\"", "style=\"background-color: #faa69d;\"").Replace("span0", "span").Replace("span1", "span").Replace("span2", "span").Replace("span3", "span").Replace("span4", "span").Replace("span5", "span"); text = text.Replace("class=\"factss\"", "style=\"background-color: #9dc6fa;\"").Replace("class=\"highls\"", "style=\"background-color: Lime;\"").Replace("class=\"orbits\"", "style=\"background-color: #f8adef;\"").Replace("class=\"ImpPss\"", "style=\"background-color: #b0ffd2;\""); } } catch { } #endregion #region CreatePdf() Method Code try { directory = HttpContext.Current.Server.MapPath("~\\SharingDoc\\"); Random generator = new Random(); int r = generator.Next(1, 1000000); string s = r.ToString().PadLeft(6, '0'); //DateTime dt = System.DateTime.Now; //string timestam = Convert.ToString(dt.Day) + Convert.ToString(dt.Month) + Convert.ToString(dt.Year) + s; //fileName = "CaseDocument_" + timestam + ".pdf"; fileName = "CaseDocument_" + ContentID + ".pdf"; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } using (var msOutput = new FileStream(directory + fileName, FileMode.Create)) { using (var document = new Document(PageSize.A4, 30, 30, 30, 30)) { using (var writer = PdfWriter.GetInstance(document, msOutput)) { document.Open(); var example_css = @".body{font-family: 'Times New Roman'}"; Font contentFont = FontFactory.GetFont("Times New Roman", 16.0f, iTextSharp.text.Font.BOLD); Paragraph para = new Paragraph(lblCaseTitle, contentFont); para.Alignment = Element.ALIGN_CENTER; document.Add(para); Paragraph para1 = new Paragraph(" ", contentFont); document.Add(para1); document.HtmlStyleClass = @".IContent{font-family: Times New Roman;text-align: justify;font-size: 22px;}"; using (TextReader reader = new StringReader(Convert.ToString(text))) { //Parse the HTML and write it to the document XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, reader); } document.Close(); } #endregion } } addWatermarkInsidePDF(fileName); } catch (Exception Ex) { fileName = string.Empty; Ex.Message.ToString(); } return(fileName); }