private void Fill_Footer(Footer footer) { var pr_date = footer.InsertParagraph(); pr_date.Append("Created: " + DateTime.Now.ToLongDateString()); var footPara = footer.InsertParagraph(); footPara.Alignment = Alignment.right; footPara.AppendPageNumber(PageNumberFormat.normal); footPara.Append("/").AppendPageCount(PageNumberFormat.normal); }
public static DocX CreateDocA(DocX template, ECEViewModel model, string source, bool cprvalue) { bool addcor = false; string Fadcorr = ""; bool special = false; string Fsnum = "[NUMBER]"; string sym = getSym(model); if (!String.IsNullOrEmpty(model.Prep)) { sym = sym.Replace("#", model.Prep.ToString()); } if (cprvalue == true) { sym = sym + "/CRP." + model.cprnum.ToString(); } if (!String.IsNullOrEmpty(model.Add) && model.cAdd == true && model.cCor == false) { sym = sym + "/Add." + model.Add.ToString(); Fadcorr = "Addendum"; addcor = true; } if (!String.IsNullOrEmpty(model.Cor) && model.cCor == true && model.cAdd == false) { sym = sym + "/Corr." + model.Cor.ToString(); Fadcorr = "Corrigendum"; addcor = true; } if (!String.IsNullOrEmpty(model.Cor) && !String.IsNullOrEmpty(model.Add) && model.cCor == true && model.cAdd == true) { sym = sym + "/Add." + model.Add.ToString() + "/Corr." + model.Cor.ToString(); Fadcorr = "Addendum Corrigendum"; addcor = true; } if (String.IsNullOrEmpty(model.Cor) && String.IsNullOrEmpty(model.Add)) { addcor = false; } if (String.IsNullOrEmpty(model.CaseYear)) { sym = sym.Replace("&", DateTime.Now.Year.ToString()); } if (!String.IsNullOrEmpty(model.CaseYear)) { sym = sym.Replace("&", model.CaseYear.ToString()); } model.tsym = sym; string[] SymStr = sym.Split('/'); string[] sym1 = SymStr.Skip(1).ToArray(); string Fsym = String.Join("/", sym1); if (Fsym.Contains("/S/")) { special = true; Fsnum = "special"; } //Create Date for Header string Fdate = model.date.ToString(); string[] d = Fdate.Split(' '); Fdate = d[0]; Fdate = formatdate(Fdate, model); //Create Distribution for Header string Fdist = getDist(model); //Create Virsions for Header string Fvirs = ""; //if (model.version1 != null) //{ // int deleteStart = 0; // int deleteEnd = 0; // //Get the array of the paragraphs containing the start and end catches // for (int i = 0; i < template.Paragraphs.Count; i++) // { // if (template.Paragraphs[i].Text.Contains("Original")) // deleteStart = i; // if (template.Paragraphs[i].Text.Contains("olang")) // deleteEnd = i; // } // if (deleteStart > 0 && deleteEnd > 0) // { // //delete from the paraIndex as the arrays will shift when a paragraph is deleted // int paraIndex = deleteStart; // for (int i = deleteStart; i <= deleteEnd; i++) // { // template.RemoveParagraphAt(paraIndex); // } // } //} //Fvirs = getVerisons(model); string Folang = ""; Folang = Olanguage(model.lang_ID); string Fatitle = "[Title]"; if (!String.IsNullOrEmpty(model.AgendaItem)) { Fatitle = model.AgendaItem.ToString(); } string Fsdate = "[Start-End Dates ]"; if (model.Sdate != null & model.Edate != null) { string sdate = model.Sdate.ToString(); string[] sd = sdate.Split(' '); sdate = sd[0]; sdate = formatdate(sdate, model); string edate = model.Edate.ToString(); string[] ed = edate.Split(' '); edate = ed[0]; edate = formatdate(edate, model); Fsdate = SessionDate(sdate, edate, model); } string Fldate = "[Start Date]"; if (model.Sdate != null & model.Edate != null) { string ldate = model.Sdate.ToString(); string[] ld = ldate.Split(' '); ldate = ld[0]; string dldate = System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.GetDayName(DateTime.Parse(ldate).DayOfWeek); ldate = formatdate(ldate, model); //Regex rx = new Regex(@"^\d+\p{Zs}", RegexOptions.Compiled); //ldate = rx.Replace(ldate, dldate+" "); ldate = dldate + " " + ldate; Fldate = ldate; } string Fanum = "[NUMBER]"; if (!String.IsNullOrEmpty(model.AgendaNum)) { Fanum = model.AgendaNum.ToString(); } if (special == false) { if (!String.IsNullOrEmpty(model.SNum)) { Fsnum = Sessionnum(model); } } if (model.qrcode == true) { string lang = language(model.lang_ID); lang = lang.Substring(0, 1); string url = "http://undocs.org/m2/QRCode.ashx?DS=" + Fsym + "&Size=2&Lang=" + lang; using (var client = new WebClient()) { //var content = client.DownloadData("https://api.qrserver.com/v1/create-qr-code/?size=66x66&data=http://undocs.org/fr/A/HRC/70"); //var content = client.DownloadData("http://undocs.org/m2/QRCode.ashx?DS=A/HRC/70&Size=2&Lang=F"); var content = client.DownloadData(url); using (var str = new MemoryStream(content)) { if (lang == "A") { Image image = template.AddImage(str); NVPicture p = image.CreatePicture(); NVFooter f = template.Footers.first; NVTable t = f.Tables[0]; //t.Rows[0].Cells[1].Paragraphs.First().AppendPicture(pR); t.Rows[0].Cells[0].Paragraphs.First().AppendPicture(p); } else { NVImage image = template.AddImage(str); NVPicture p = image.CreatePicture(); NVFooter f = template.Footers.first; NVTable t = f.Tables[0]; //t.Rows[0].Cells[1].Paragraphs.First().AppendPicture(pR); t.Rows[0].Cells[1].Paragraphs.First().AppendPicture(p); } } } } string Fcategory = ""; Fcategory = getCat(model.Cat); string FSubcategory = ""; if (model.SCat != "Not Applicable" || model.SCat != "Special Session") { FSubcategory = model.SCat.ToString(); } if (model.SCat == "Not Applicable" || model.SCat == "Special Session") { int deleteStart = 0; int deleteEnd = 0; //Get the array of the paragraphs containing the start and end catches for (int i = 0; i < template.Paragraphs.Count; i++) { if (template.Paragraphs[i].Text.Contains("subcategory")) { deleteStart = i; } if (template.Paragraphs[i].Text.Contains("subcategory")) { deleteEnd = i; } } if (deleteStart > 0 && deleteEnd > 0) { //delete from the paraIndex as the arrays will shift when a paragraph is deleted int paraIndex = deleteStart; for (int i = deleteStart; i <= deleteEnd; i++) { template.RemoveParagraphAt(paraIndex); } } } if (addcor == false) { int deleteStart = 0; int deleteEnd = 0; //Get the array of the paragraphs containing the start and end catches for (int i = 0; i < template.Paragraphs.Count; i++) { if (template.Paragraphs[i].Text.Contains("adcorr")) { deleteStart = i; } if (template.Paragraphs[i].Text.Contains("adcorr")) { deleteEnd = i; } } if (deleteStart > 0 && deleteEnd > 0) { //delete from the paraIndex as the arrays will shift when a paragraph is deleted int paraIndex = deleteStart; for (int i = deleteStart; i <= deleteEnd; i++) { template.RemoveParagraphAt(paraIndex); } } } string Fsplace = "[Session City]"; if (!String.IsNullOrEmpty(model.splace)) { Fsplace = model.splace.ToString(); } string Floca = "[Session Location]"; if (!String.IsNullOrEmpty(model.loca)) { Floca = model.loca.ToString() + ", " + Fsplace; } DateTime x = DateTime.Now; string[] info1 = info(model); template.AddCustomProperty(new CustomProperty("sym1", Fsym)); template.AddCustomProperty(new CustomProperty("symh", sym)); template.AddCustomProperty(new CustomProperty("dist", Fdist)); template.AddCustomProperty(new CustomProperty("date", Fdate)); template.AddCustomProperty(new CustomProperty("sdate", Fsdate)); template.AddCustomProperty(new CustomProperty("virs", Fvirs)); template.AddCustomProperty(new CustomProperty("snum", Fsnum)); template.AddCustomProperty(new CustomProperty("anum", Fanum)); template.AddCustomProperty(new CustomProperty("adcorr", Fadcorr)); template.AddCustomProperty(new CustomProperty("gdoc", "")); template.AddCustomProperty(new CustomProperty("gdocf", "")); template.AddCustomProperty(new CustomProperty("tlang", "")); template.AddCustomProperty(new CustomProperty("atitle", Fatitle)); template.AddCustomProperty(new CustomProperty("ldate", Fldate)); template.AddCustomProperty(new CustomProperty("loca", Floca)); template.AddCustomProperty(new CustomProperty("categ", Fcategory)); template.AddCustomProperty(new CustomProperty("subcategory", FSubcategory)); template.AddCustomProperty(new CustomProperty("splace", Fsplace)); template.AddCustomProperty(new CustomProperty("olang", Folang)); template.AddCustomProperty(new CustomProperty("Date-Generated", x)); template.AddCustomProperty(new CustomProperty("Org", "ECE")); template.AddCustomProperty(new CustomProperty("Entity", info1[0])); template.AddCustomProperty(new CustomProperty("doctype", info1[1])); template.AddCustomProperty(new CustomProperty("category", info1[2])); template.AddCustomProperty(new CustomProperty("bar", "")); for (int i = 0; i < template.Paragraphs.Count; i++) { if (template.Paragraphs[i].Text.Contains(Fsnum)) { string Fsnum1 = char.ToUpper(Fsnum[0]) + Fsnum.Substring(1); template.Paragraphs[i].ReplaceText(Fsnum, Fsnum1); break; } } if (addcor == true && cprvalue == false) { int deleteStart = 0; int deleteEnd = 0; //Get the array of the paragraphs containing the start and end catches for (int i = 0; i < template.Paragraphs.Count; i++) { if (template.Paragraphs[i].Text.Contains("*")) { deleteStart = i; } if (template.Paragraphs[i].Text.Contains(Fadcorr)) { deleteEnd = i; } } if (deleteStart > 0 && deleteEnd > 0) { //delete from the paraIndex as the arrays will shift when a paragraph is deleted int paraIndex = deleteEnd - deleteStart; paraIndex = deleteStart + paraIndex - 1; template.RemoveParagraphAt(paraIndex); } //List <string> replace = template.FindUniqueByPattern("*", RegexOptions.None); //foreach (string s in replace) //{ // if (!s.Equals("")) template.ReplaceText((s, ""); //} template.ReplaceText("*", ""); List <string> repl = template.FindUniqueByPattern(",\\s", RegexOptions.None); foreach (string rep in repl) { if (!String.IsNullOrEmpty(rep)) { template.ReplaceText(rep, ""); } } //bool flag = false; //List<List<string>> list1 = new List<List<string>>(); //List<string> list2 = new List<string>(); //foreach (Novacode.Paragraph item in template.Paragraphs) //{ // //use this if you need whole text of a paragraph // string paraText = item.Text; // var result = paraText.Split(' '); // int count = 0; // list2 = new List<string>(); // //use this if you need word by word // foreach (var data in result) // { // string word = data.ToString(); // if (word.Contains(Fsnum)) flag = true; // if (word.Contains("session")) // { // flag = false; // // list2.Add(word); // } // if (flag) // list2.Add(word); // count++; // } // // list2.RemoveAt(0); // list1.Add(list2); //} //// list1[0].Replace(list1[0], "*"); //for (int i = 0; i < list1.Count(); i++) //{ // string temp = ""; // for (int y = 0; y < list1[i].Count(); y++) // { // if (y == 0) // { // temp = list1[i][y]; // continue; // } // temp += " " + list1[i][y]; // // temp = temp.Remove(temp.IndexOf(',')-1, temp.Length); // } // int ind = temp.IndexOf("*"); // // temp = temp.Substring(ind, temp.Length - ind); // if (!temp.Equals("")) template.ReplaceText("Done", ""); //} } //using (WordprocessingDocument // document = WordprocessingDocument.Open(source, true)) //{ // var bookMarks = FindBookmarks(document.MainDocumentPart.Document); //} // Return the template now that it has been modified to hold all of our custom data. return(template); }