public FlattenedSection FlattenSection(Section section) { var words = section.SectionText.Split(' '); FlattenedSection flatSection = new FlattenedSection { SectionId = section.SectionId, DatasheetId = section.DatasheetId, StringSections = new List<StringSection>(words.Length * (words.Length -1)) }; for (int i = 0; i < words.Length; i++) { StringBuilder builder = new StringBuilder(); //add all words before to before this string and save for (int j = i; j > -1; j--) //iterate backwards from current word to beginning { builder.Insert(0,words[j]); //add the word at j flatSection.StringSections.Add(FlattenWord(builder.ToString(),section.DatasheetId,flatSection.SectionId)); builder.Insert(0, ' '); } builder.Clear(); //add all words to after this string and save for (int j = i; j < words.Length; j++) { builder.Append(words[j]); flatSection.StringSections.Add(FlattenWord(builder.ToString(),section.DatasheetId,section.SectionId)); builder.Append(' '); } } return flatSection; }
private Task StartWordWithPdfAdProcess() { var pdfBytes = System.IO.File.ReadAllBytes(_filePath); using (NetOffice.WordApi.Application app = new NetOffice.WordApi.Application()) { #if DEBUG app.Visible = true; #endif var doc = app.Documents.Open(_filePath); var datasheet = new Datasheet.Dal.Ef.Datasheet { FilePath = _filePath, Pdf = pdfBytes, PdfProvider = GetInstanceName(_filePath), }; foreach (var section in doc.Paragraphs) { var newSection = new Section { }; datasheet.Sections.Add(newSection); if (!String.IsNullOrEmpty(section.Range.Text) && ! String.IsNullOrWhiteSpace(section.Range.Text)) { newSection.SectionText = section.Range.Text; } else { //Extract image! //newSection.SectionImage = section.Range. } } app.Quit(); _context.Datasheets.Add(datasheet); return _context.SaveChangesAsync(); } }