Hi
Thanks for your inquiry. I think, you can use DocumentVisitor to achieve what you need. For example, please try using the following code:
Document doc = new Document(@"Test001\source.doc");
ParagraphResolver resolver = new ParagraphResolver();
doc.Accept(resolver);
doc.Save(@"Test001\out.doc");
doc.Save(@"Test001\out.epub");
=======================================================
private class ParagraphResolver : DocumentVisitor
{
public override VisitorAction VisitParagraphEnd(Paragraph paragraph)
{
// Get next node after the paragraph.
CompositeNode nextNode = (CompositeNode)paragraph.NextSibling;
// If paragraph is empty and the next node is also enpty paragraph, remove the paragraph.
if (!paragraph.HasChildNodes && nextNode != null && !nextNode.HasChildNodes)
{
paragraph.Remove();
}
// If both paragraphs are not empty, concatenate them
else if (paragraph.HasChildNodes && nextNode != null && nextNode.NodeType == NodeType.Paragraph && nextNode.HasChildNodes)
{
// If the next paragraph starts with tab, remove it.
if (nextNode.FirstChild.NodeType == NodeType.Run)
{
Run run = (Run)nextNode.FirstChild;
run.Text = run.Text.StartsWith("\t") ? run.Text.Substring(1) : run.Text;
}
foreach (Node node in nextNode.ChildNodes)
paragraph.AppendChild(node);
}
return VisitorAction.Continue;
}
}
Hope this helps.
Best regards,
Alexey Noskov
Developer/Technical Support
Aspose Auckland Team