diff --git a/Src/xWorks/LcmWordGenerator.cs b/Src/xWorks/LcmWordGenerator.cs index d7589d7667..c5194a12e7 100644 --- a/Src/xWorks/LcmWordGenerator.cs +++ b/Src/xWorks/LcmWordGenerator.cs @@ -71,6 +71,7 @@ public static void SavePublishedDocx(int[] entryHvos, DictionaryPublicationDecor { ContentGenerator = generator, StylesGenerator = generator}; settings.StylesGenerator.AddGlobalStyles(configuration, readOnlyPropertyTable); string lastHeader = null; + bool firstHeader = true; string firstGuidewordStyle = null; var entryContents = new Tuple[entryCount]; var entryActions = new List(); @@ -112,7 +113,8 @@ public static void SavePublishedDocx(int[] entryHvos, DictionaryPublicationDecor if (!entry.Item2.IsNullOrEmpty()) { IFragment letterHeader = GenerateLetterHeaderIfNeeded(entry.Item1, - ref lastHeader, col, settings, readOnlyPropertyTable, propStyleSheet, clerk); + ref lastHeader, col, settings, readOnlyPropertyTable, propStyleSheet, firstHeader, clerk ); + firstHeader = false; // If needed, append letter header to the word doc if (!letterHeader.IsNullOrEmpty()) @@ -234,13 +236,13 @@ public static void SavePublishedDocx(int[] entryHvos, DictionaryPublicationDecor internal static IFragment GenerateLetterHeaderIfNeeded(ICmObject entry, ref string lastHeader, Collator headwordWsCollator, ConfiguredLcmGenerator.GeneratorSettings settings, ReadOnlyPropertyTable propertyTable, LcmStyleSheet mediatorStyleSheet, - RecordClerk clerk = null) + bool firstHeader, RecordClerk clerk = null) { StringBuilder headerTextBuilder = ConfiguredLcmGenerator.GenerateLetterHeaderIfNeeded(entry, ref lastHeader, headwordWsCollator, settings, clerk); // Create LetterHeader doc fragment and link it with the letter heading style. - return DocFragment.GenerateLetterHeaderDocFragment(headerTextBuilder.ToString(), WordStylesGenerator.LetterHeadingDisplayName); + return DocFragment.GenerateLetterHeaderDocFragment(headerTextBuilder.ToString(), WordStylesGenerator.LetterHeadingDisplayName, firstHeader); } /* @@ -308,22 +310,27 @@ public DocFragment(string str) : this() /// /// Letter header string. /// Letter header style name to display in Word. - internal static DocFragment GenerateLetterHeaderDocFragment(string str, string styleDisplayName) + /// True if this is the first header being written. + internal static DocFragment GenerateLetterHeaderDocFragment(string str, string styleDisplayName, bool firstHeader) { var docFrag = new DocFragment(); // Only create paragraph, run, and text objects if string is nonempty if (!string.IsNullOrEmpty(str)) { - // Everything other than the Letter Header should be 2 columns. Create a empty - // paragraph with two columns for the last paragraph in the section that uses 2 - // columns. (The section is all the entries after the previous letter header.) - var sectProps2 = new SectionProperties( - new HeaderReference() { Id = WordStylesGenerator.PageHeaderIdEven, Type = HeaderFooterValues.Even }, - new HeaderReference() { Id = WordStylesGenerator.PageHeaderIdOdd, Type = HeaderFooterValues.Default }, - new Columns() { EqualWidth = true, ColumnCount = 2 }, - new SectionType() { Val = SectionMarkValues.Continuous } - ); - docFrag.DocBody.AppendChild(new WP.Paragraph(new WP.ParagraphProperties(sectProps2))); + // Don't add this paragraph before the first letter header. It results in an extra blank line. + if (!firstHeader) + { + // Everything other than the Letter Header should be 2 columns. Create a empty + // paragraph with two columns for the last paragraph in the section that uses 2 + // columns. (The section is all the entries after the previous letter header.) + var sectProps2 = new SectionProperties( + new HeaderReference() { Id = WordStylesGenerator.PageHeaderIdEven, Type = HeaderFooterValues.Even }, + new HeaderReference() { Id = WordStylesGenerator.PageHeaderIdOdd, Type = HeaderFooterValues.Default }, + new Columns() { EqualWidth = true, ColumnCount = 2 }, + new SectionType() { Val = SectionMarkValues.Continuous } + ); + docFrag.DocBody.AppendChild(new WP.Paragraph(new WP.ParagraphProperties(sectProps2))); + } // Create the letter header in a paragraph. WP.ParagraphProperties paragraphProps = new WP.ParagraphProperties(new ParagraphStyleId() { Val = styleDisplayName });