This demo uses the DevExpress Word Processing Document API to format document paragraphs. You can process the predefined sample file or supply your own document. To do the latter, select Upload a File in the file selection drop-down menu.
Specify the required formatting parameters in the panel below. Use the Format Paragraphs and Save as... dropdown button to select the output format, apply changes, and download the result.
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using System.Drawing;
void FormatParagraph(Document document, DocumentRange range, Color shading, ParagraphAlignment alignment,
float lineSpacingMultiplier, float leftIndent, bool widowOrphanControl, bool keepWithNext, bool KeepLinesTogether) {
ParagraphProperties pp = document.BeginUpdateParagraphs(range);
pp.BackColor = shading;
pp.Alignment = alignment;
pp.LineSpacingType = ParagraphLineSpacing.Multiple;
pp.LineSpacingMultiplier = lineSpacingMultiplier;
pp.LeftIndent = leftIndent;
pp.WidowOrphanControl = widowOrphanControl;
pp.KeepWithNext = keepWithNext;
pp.KeepLinesTogether = KeepLinesTogether;
document.EndUpdateParagraphs(pp);
}
void ResetParagraphFormatting(Document document, DocumentRange range, ParagraphPropertiesMask resetParagraphProperties) {
ParagraphProperties cp = document.BeginUpdateParagraphs(range);
cp.Reset(resetParagraphProperties);
document.EndUpdateParagraphs(cp);
}
void FormatParagraphBorders(Document document, DocumentRange range, float lineWidth, BorderLineStyle lineStyle, Color borderColor) {
ParagraphProperties pp = document.BeginUpdateParagraphs(range);
SetParagraphBorder(pp.Borders.HorizontalBorder, lineWidth, lineStyle, borderColor);
SetParagraphBorder(pp.Borders.BottomBorder, lineWidth, lineStyle, borderColor);
SetParagraphBorder(pp.Borders.TopBorder, lineWidth, lineStyle, borderColor);
SetParagraphBorder(pp.Borders.LeftBorder, lineWidth, lineStyle, borderColor);
SetParagraphBorder(pp.Borders.RightBorder, lineWidth, lineStyle, borderColor);
document.EndUpdateParagraphs(pp);
}
void SetParagraphBorder(ParagraphBorder border, float lineWidth, BorderLineStyle lineStyle, Color borderColor) {
border.LineWidth = lineWidth;
border.LineStyle = lineStyle;
border.LineColor = borderColor;
}