Regarding Novacode Docx: How do I add soft returns within paragraphs

1.2k Views Asked by At

I am using the Novacode DocX c# library to create word documents and have run into a problem. I want my paragraphs to 'keep together' at page breaks. But, I also want to use soft returns to force my pictures to display vertically between lines of text.

So my question is, how do I add soft returns within paragraphs?

2

There are 2 best solutions below

0
On

You can try to add one of those unicode char at the end of your paragraph, for instance :

using (DocX document = DocX.Create(@"docs\myDoc.docx"))
{
    Paragraph p = document.Paragraphs[0];
    p.Append("\u000D");
    p.Append("\u000A");
}

Tell me if it solves your problem

0
On

I solved this with:

using (DocX document = DocX.Create(@"docs\myDoc.docx"))
{
    Paragraph p = document.Paragraphs[0];
    p.Append("\u000D");
}

Note: this is adapted from @G.Dealmeida's answer. If you include the additional \u000A then you get a second line break.