Darin Sease
Darin Sease

Reputation: 93

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

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?

Upvotes: 9

Views: 1276

Answers (2)

ChrisFox
ChrisFox

Reputation: 346

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.

Upvotes: 0

G.Dealmeida
G.Dealmeida

Reputation: 335

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

Upvotes: 1

Related Questions