Implement Line Spacing Single- Sesquilateral- Double

Hi,

Currently Aspose.Words.LineSpacingRule doesn’t implement Single, Sesquilateral and Double. Please implement those.

Thanks,

Christophe

Hi Christophe,

Thanks for your inquiry. I have logged this feature request as WORDSNET-11441 in our issue tracking system. You will be notified via this forum thread once this feature is available.

We apologize for your inconvenience.

Thanks Tahir!

Hi Christophe,

Thanks for your patience. Aspose.Words supports the requested feature. You can use LineSpacingRule.Multiple to specify line
spacing 1.5 line, 2 line, 2.5 line etc. Please check the following code example for your kind reference.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Specify linespacing 1.5 line
builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple;
// The line spacing is specified in the LineSpacing property as the number of lines.
// One line equals 12 points. so 1.5 lines = 18 points
builder.ParagraphFormat.LineSpacing = 18;
// Insert some text
builder.Writeln("This is paragraph with '1.5 line' spacing rule");
// The same technique you can use to specify Document spacing rule
builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple;
builder.ParagraphFormat.LineSpacing = 24;
builder.Writeln("This is paragraph with 'Double' spacing rule");
builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple;
builder.ParagraphFormat.LineSpacing = 36;
builder.Writeln("This is paragraph with 'Multiple' spacing rule");
builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.AtLeast;
builder.ParagraphFormat.LineSpacing = 12;
builder.Writeln("This is paragraph with 'AtLeast' spacing rule");
builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly;
builder.ParagraphFormat.LineSpacing = 10;
builder.Writeln("This is paragraph with 'Exactly' spacing rule");
doc.Save(MyDir + "Out.docx");

Tahir,

This is a workaround that might work in some cases but not in our current scenario. If I create the document in Word with a Single, Sesquialteral or Double line spacing, then edit it via Aspose using your suggestion, the setting is lost after saving the document.

I need to retain it.

Hi Christophe,

Thanks for your inquiry.

*info@pts.lu:

Currently Aspose.Words.LineSpacingRule doesn’t implement Single, Sesquilateral and Double. Please implement those.*

This feature already exists in Aspose.Words. So, we have closed WORDSNET-11441.

*info@pts.lu:

This is a workaround that might work in some cases but not in our current scenario. If I create the document in Word with a Single, Sesquialteral or Double line spacing, then edit it via Aspose using your suggestion, the setting is lost after saving the document.*

I have tested the scenario using latest version of Aspose.Words for .NET 15.2.0 and have not found this issue. I have attached the code and input/output documents with this post for your kind reference.

Document doc = new Document(MyDir + "LineSpacingRule.docx");
Paragraph para1 = (Paragraph)doc.GetChild(NodeType.Paragraph, 0, true);
para1.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple;
para1.ParagraphFormat.LineSpacing = 18;
Paragraph para2 = (Paragraph)doc.GetChild(NodeType.Paragraph, 1, true);
para2.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple;
para2.ParagraphFormat.LineSpacing = 24;
doc.Save(MyDir + "Out.docx");

If you still face problem, please share following detail for investigation purposes.

  • Please attach your input Word document.
  • Please

create a standalone/runnable simple application (for example a Console
Application Project
) that demonstrates the code (Aspose.Words code) you used to generate
your output document

  • Please attach the output Word file that shows the undesired behavior.
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated
    like.

As soon as you get these pieces of information to
us we’ll start our investigation into your issue.

Hi Tahir,

Yes, sorry, in fact the scenario is much more complex
than that. But the gist of it is that I open a file via Aspose, then
give the possibility to edit the file’s formatting via a custom GUI. The problem is that if in Word I specify for example Single
for the Linespacing, then open the file via Aspose, then edit the
setting in my GUI, in the GUI I see Multiple instead of Single:

http://screencast.com/t/F3n9IOiZ4x41

For Word, Single (and also Sesquialteral, Double) are a completely different setting than Multiple with a point size of twelve.

Test project added as an attachement…

Hi Christophe,

Thanks for your inquiry. Please use following code example to achieve your requirements.

Document doc = new Document(MyDir + "LineSpacingRule.docx");
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
    if (para.ParagraphFormat.LineSpacing == 12 && para.ParagraphFormat.LineSpacingRule == LineSpacingRule.Multiple)
    {
        Console.WriteLine("Single");
    }
    else if (para.ParagraphFormat.LineSpacing == 18 && para.ParagraphFormat.LineSpacingRule == LineSpacingRule.Multiple)
    {
        Console.WriteLine("1.5 Lines");
    }
    else if (para.ParagraphFormat.LineSpacing == 24 && para.ParagraphFormat.LineSpacingRule == LineSpacingRule.Multiple)
    {
        Console.WriteLine("Double");
    }
    else if (para.ParagraphFormat.LineSpacing > 24 && para.ParagraphFormat.LineSpacingRule == LineSpacingRule.Multiple)
    {
        Console.WriteLine("Multiple");
    }
}

Please check following detail of LineSpacingRule enumeration from here:

Multiple : The line spacing is specified in the LineSpacing property as the number of lines. **One line equals 12 points.

Exactly** :
The line spacing never changes from the value specified in the
LineSpacing property, even if a larger font is used within the
paragraph.

AtLeast : The line spacing can be greater than or equal to, but never less than, the value specified in the LineSpacing property.

Hi Tahir,

Your proposal leads to the opposite problem. If in Word I specify Linespacing = Multiple and line size of 12 points, using your code in my GUI I’ll get Single instead of Linespacing = Multiple, 12. So there is information that is lost.

I had the feeling that adding the missing constants and supporting them in Aspose wouldn’t be a big problem, but maybe I’m wrong and missing something?

Regards,

Christophe

Hi Christophe,

Thanks for your inquiry. Please note that Aspose.Words mimics the same behaviour as MS Word does. If you set the line spacing as ‘Multiple’ and line size as 12 in MS Word, the output will be ‘Single’ line space. Similarly, if you set the line spacing as ‘Multiple’ and line size as 14, the output will be ‘Double’. Please check this behavior in MS Word. Aspose.Words does the same.

Please check the detail of LineSpacingRule enumeration in my previous post. Hope this answer your query.

Hi Tahir,

Well I stand corrected. I tested the behaviour in Word and you are correct. So I’ll follow your suggestion.

Thanks,

Christophe

Hi Christophe,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.