Hi,
After performing some MergeFields merging, my document ends up with many carriage returns and empty characters.
I write some lines of code to remove carriage returns if the following line of the current line has no text (ie we have 2 consecutive lines without any text):
// Remove all carriage returns that have no text var paragraphs = document.GetChildElements(true, ElementType.Paragraph).Cast<Paragraph>().ToList(); for (var i = 0; i <= paragraphs.Count() - 1; i++) { if (paragraphs[i].Content.CountWords() == 0) { // Only remove carriage return if the next paragraph is also empty if (i < paragraphs.Count() - 1 && paragraphs[i + 1].Content.CountWords() == 0) { paragraphs[i].Content.Delete(); } } }
Unfortunately, “ElementType.Paragraph” also includes the document header and footer so if my header includes a logo (picture), it gets removed.
Question: how can I select all the paragraphs except the header and footer?
Thanks.