Line Spacing

Oct 29, 2013 at 4:52 PM
This is such an awesome library, thank you for creating it!

The only thing I can't get to work is line spacing. There has to be some way to change between single space, double space, etc. There are methods Spacing(), SpacingAfter(), SpacingBefore on the Paragraph class, but these don't appear to affect anything.

Nov 1, 2013 at 12:58 PM
You should be able to use the following to set a Paragraph's LineSpacing to 1,5:
par.LineSpacing = 1.5f;
However, I found this changes the spacing between words rather than between lines. Unless I am mistaken, I would say Line Spacing means the distance between the lines of a paragraph, not the distance between the words in a paragraph.

If you want to change the distance between the lines of a paragraph, I just uploaded a patch that enables you to do so using the method SetLineSpacing.
It can be used like this:
// Use the default type, Line, to set spacing between lines
par.SetLineSpacing(LineSpacingType.Line, 1.5f);

// Use one argument to set the spacing to Auto. Can be used to set Before, After and both using Auto

// Use the type None to remove spacing
Hope this helps
Marked as answer by tsedeq3 on 11/1/2013 at 7:49 AM
Nov 1, 2013 at 3:49 PM
Wow! I just applied your patch, works great, thank you!
Nov 5, 2013 at 10:41 AM
Added to main source. Thanks Annika89. As always great work!
Jan 14, 2014 at 2:28 AM
Can you please tell me how do I apply the patch?
Jan 14, 2014 at 9:09 AM
The patch has already been applied to the latest source code. You can download the source code and build your own dll from there.

Or, if you already have a project based on the DocX source code, you could download the patch . You can either simply copy the code into the Paragraph.cs file (though I think you might have to remove some +'s) or you could use TortoiseSVN (which I used to create the patch) to apply the patch.

Might be there are more ways to accomplish this, I'm only familiar with these options.
Jan 16, 2014 at 4:26 PM
Awesome! thanks a lot! :) :)
Jun 2, 2014 at 5:09 AM
thatnks for the updates for paragraph spacing Annika89,... but i wonder,

why when i add that code to my code on these codes, it gives me error?

my code
 Private Sub addParagraphSpacing(ByVal sText As String, ByVal n As DocX, ByVal sAlignment As Alignment, ByVal sForm As Novacode.Formatting, ByVal dSPacing As Double)
        Dim par As Novacode.Paragraph = n.InsertParagraph()
        par.LineSpacing = dSPacing
        par.InsertText(sText, False, sForm)
        par.Alignment = sAlignment
    End Sub
Whereas the dSPacing is actually 1.5f value.

Jun 2, 2014 at 1:08 PM
Edited Jun 2, 2014 at 1:09 PM
To set the linespacing, I would suggest using this code:
par.SetLineSpacing(LineSpacingType.Line, dSPacing)
//Instead of par.LineSpacing = dSPacing | LineSpacingType can also be After or Before
I didn't edit the original method of setting the LineSpacing value directly. I don't get an error when I use .LineSpacing though, for me it sets the spacing between letters rather than the spacing between lines.

I suspect the "Unexpected error" might be caused by something else (if changing the lines above doesn't help). Could you provide the XML from line 10 of your document.xml file, if you're still getting the error? (Perhaps just the part that's giving the error, around column 3198.)
Jun 9, 2014 at 8:48 PM
I have downloaded the latest version of DocX but i can not get the lineSpacing working. Also the setLineSpacing method is not apearing either. Can you please help or point me to a different download.
Jun 9, 2014 at 9:20 PM
Download the source code and compile it. The binary version is old and doesn't have what Annika89 describes.
Jun 9, 2014 at 9:39 PM
Where can this code be found. And where do I need to add it to. Thanks
Jun 10, 2014 at 9:06 AM
At the top of the CodePlex page, there's a "Source Code" tab, at the "Source Code" screen you'll find a "Download" button where you can download the DocX project.
Then open the downloaded project and compile it into your own DocX.dll to reference in your project. Alternatively, you could add the DocX project to your own solution and referende that project.