Question

I am wondering if there's a way to avoid line breaking between certain paragraphs. For example:

Paragraph PjourneyTitle = sec.AddParagraph(journeyTitle, "Heading2");
Paragraph Pjourney = sec.AddParagraph();
Pjourney.Format.Font.Bold = true;
Pjourney.AddText(offer.Destination);

Between PjourneyTitle and Pjourney there's a line break occuring, which I would like to avoid.

I've been googling all day today to no avail.

Any help is greatly appreciated. Thanks in advance!

EDIT: After using the code suggested by you guys: This does not seem to work for me... whatever the reason. While it KeepWithNext seems to be an option in ParagraphFormat, setting it to true does nothing for me. I'm setting a Style (Heading2) which I use in my MigraDoc code like posted above.

Here's the Style Code for Heading2:

style = document.Styles["Heading2"];
style.ParagraphFormat.LeftIndent = "0cm";
style.ParagraphFormat.KeepWithNext = true;
//style.ParagraphFormat.KeepTogether = true;
style.Font.Size = 10;
style.Font.Bold = true;
style.ParagraphFormat.PageBreakBefore = false;
style.ParagraphFormat.SpaceBefore = 6;
style.ParagraphFormat.SpaceAfter = 6;
Was it helpful?

Solution

KeepWithNext will assure that the last line of the first paragraph and the first line of the second paragraph will be on the same page. So it prevents pagebreaks between those two paragraphs, but does not prevent pagebreaks inside the paragraph.

KeepTogether will prevent pagebreaks inside the paragraph.

If you want to treat both paragraphs as an unbreakable block, using KeepTogether on both Paragraphs and KeepWithNext on the first paragraph should do the trick.

It's by design that each paragraph starts on a new line. There is no way to prevent line breaks between paragraphs (sorry, I should have read that question more carefully).

You can use AddFormattedText to mix different formats (e.g. bold and normal) within a paragraph.

You can use a table (maybe with hidden borders) to have two different columns.

So depending on your needs, AddFormattedText or a table may be the best option.

OTHER TIPS

I think you're looking for the keepWithNext property. Set that to true.

http://msdn.microsoft.com/en-us/library/system.windows.documents.paragraph.keepwithnext.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top