How is it possible to apply "No Paragraph Space" option to a Word document in WPF?
Microsoft Word lets the user apply the “No Paragraph Space” option to the entire Word document. The same can be achieved using WPF DocIO as well. The “No Paragraph Space” option should have the following properties:
Property Name | Value |
Before Spacing | 0 |
After Spacing | 0 |
Line Spacing | Single |
In Microsoft Word, you can find this option in the following location:
Go to the Design Ribbon -> Click the down arrow of “Paragraph Spacing” under “Document Formatting” -> Click “No Paragraph Space.” When you choose this option, the above properties will be applied to the “Normal” style and will be reflected in the paragraphs that are applied with the “Normal” style. You can achieve the same using DocIO by applying the above properties to the “Normal” style.
Please refer to the screenshot below to set the “No Paragraph Space” option in Microsoft Word:
Limitations:
If any paragraphs are applied with direct formatting, then that will be considered rather than the definitions from the “Normal” style, according to Microsoft Word document specification.
Kindly use the below code to set “No Paragraph Space” option to the Normal style using DocIO.
C#:
// Loading Word document
WordDocument document = new WordDocument("filename.docx");
// Gets the normal style which is the base of other styles
WParagraphStyle style = document.Styles.FindByName("Normal") as WParagraphStyle;
// Sets before spacing value
style.ParagraphFormat.BeforeSpacing = 0;
// Sets after spacing value
style.ParagraphFormat.AfterSpacing = 0;
// The below two lines of code set line spacing to single. The line spacing rule "Multiple" with value 12 sets the line spacing to "Single"
style.ParagraphFormat.LineSpacingRule = Syncfusion.DocIO.LineSpacingRule.Multiple;
style.ParagraphFormat.LineSpacing = 12;
// Saves the Word document
document.Save("filename.docx");
VB:
Dim document As New WordDocument("filename.docx")
' Gets the normal style which is the base of other styles
Dim style As WParagraphStyle = TryCast(document.Styles.FindByName("Normal"), WParagraphStyle)
' Sets before spacing value
style.ParagraphFormat.BeforeSpacing = 0
' Sets after spacing value
style.ParagraphFormat.AfterSpacing = 0
' The below two lines of code set line spacing to single. The line spacing rule "Multiple" with value 12 sets the line spacing to "Single"
style.ParagraphFormat.LineSpacingRule = Syncfusion.DocIO.LineSpacingRule.Multiple
style.ParagraphFormat.LineSpacing = 12
' Saves the Word document
document.Save("filename.docx")
Conclusion
I hope you enjoyed learning about how it is possible to apply the "No Paragraph Space" option to a Word document in WPF.
You can refer to our WPF Word Document feature tour page to learn about its other groundbreaking features and documentation, and how to quickly get started with configuration specifications.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to explore our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!