Reset the 'ParagraphFormat.LeftIndent' value

Hi,

The issue is I have converted the Html to Word, the list bullet symbol is moved to more right side. So I want reset ‘ParagraphFormat.LeftIndent’ value. And my document contains ‘two’List Level’.
I have attached the document & html.

Thanks.

Hi Mani,

Thanks for your inquiry. Please use ListFormat.ListLevelNumber property to get or set the list level number (0 to 8) for the paragraph. In your case, we suggest you please set the value of ParagraphFormat.LeftIndent when value of ListFormat.ListLevelNumber is 1.

You may use following code example to get the desired output. If you still face problem, please share your expected output document here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.

Document doc = new Document(MyDir + "in.html");
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
    if (para.IsListItem)
    {
        int ListLevelNumber = para.ListFormat.ListLevelNumber;
        List list = para.ListFormat.List;
        para.ParagraphFormat.ClearFormatting();
        para.ListFormat.ListLevelNumber = ListLevelNumber;
        para.ListFormat.List = list;
    }
}
doc.Save(MyDir + "17.4.docx");

Hi Tahir Manzoor,

Thanks for your response. I have tried your solution. From word to word merge, I got exact result. But from html to word, the list is move to little more right side.
I have attached my output. Could you please suggest us?

Thanks.

Hi Mani,

Thanks for your inquiry. You can use ParagraphFormat.LeftIndent to set the left indentation of paragraph. However, we suggest you please use ListLevel.NumberPosition and ListLevel.TextPosition properties to achieve your requirements.

If you face any issue, please share your expected output document. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.

Document doc = new Document(MyDir + "in.html");
List list = null;
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
    if (para.IsListItem)
    {
        int ListLevelNumber = para.ListFormat.ListLevelNumber;
        list = para.ListFormat.List;
        para.ParagraphFormat.ClearFormatting();
        para.ListFormat.ListLevelNumber = ListLevelNumber;
        para.ListFormat.List = list;
    }
}
list.ListLevels[1].NumberPosition -= 10;
list.ListLevels[1].TextPosition -= 10;
doc.Save(MyDir + "17.4.docx");

Hi Tahir Manzoor,

Thanks for your response.

Thanks & Regards,
Mani.

Hi Tahir Manzoor,

I have tried your solution. But I could not achieve my requirement. I have attached my input html & result document. Could you please suggest us.

Thanks,
Mani.

Hi Mani,

Thanks for your inquiry. Please note that the paragraph formatting is different in both HTML and DOC input documents. If you decrease the value of left indent of paragraphs for both documents, you will get the different output.

As per my understanding, you are using the same code for both input documents. We suggest you please create a new list and apply it to paragraphs as shown below. Hope this helps you.

If this does not help you, please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will then provide you more information on this along with code.

Document doc = new Document(MyDir + "Input_TestDocument.html");
List list = doc.Lists.Add(ListTemplate.NumberArabicDot);
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
    if (para.IsListItem)
    {
        int ListLevelNumber = para.ListFormat.ListLevelNumber;
        para.ParagraphFormat.ClearFormatting();
        para.ListFormat.ListLevelNumber = ListLevelNumber;
        para.ListFormat.List = list;
    }
}
doc.Save(MyDir + "17.4.docx");

Hi Tahir Manzoor,

Thanks for your response, we have a lot of html documents. I need to merge all html documents using my template word document. It contains my own paragraph styles. After merging the document from html, I want to retain my paragraph style name. Because my html and template word contain same ‘List’ paragraph style name(Html-CSS-ClassName==WordListParagraphName).

Issue : After merging the document, my list paragraph(bullet symol) is moved litle right. But When I create a list style in my document, it starts at a different position.
Example: The paragraph ‘Style selected directly in Word’. Style: ‘KurzListe’

Thanks & Regards,
Mani.

Hi Mani,

Thanks for your inquiry.

Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing. We will investigate the issue on our side and provide you more information.

Hi Tahir Manzoor,

Thanks for your response, I have attached the console application. Could you please suggest us.

Thanks & Regards,
Mani.

Hi Mani,

Thanks for sharing the detail. In case you are using older version of Aspose.Words, we suggest you please upgrade to the latest version of Aspose.Words for .NET 17.4.

Please use following code example to achieve your requirement. In your case, the style name in HTML and template document should be same. We have attached the input and output documents with this post for your kind reference.

Document doc = new Document(MyDir + "Template.doc");
Document docInclude = new Document(MyDir + "Input_Html.htm");
foreach (Paragraph paragraph in docInclude.GetChildNodes(NodeType.Paragraph, true))
{
    string strStyleName = paragraph.ParagraphFormat.StyleName;
    if (paragraph.IsListItem)
    {
        int ListLevelNumber = paragraph.ListFormat.ListLevelNumber;
        paragraph.ParagraphFormat.ClearFormatting();
        paragraph.ParagraphBreakFont.ClearFormatting();
        foreach (Run run in paragraph.Runs)
        {
            run.Font.ClearFormatting();
        }
        paragraph.ParagraphFormat.StyleName = strStyleName;
        Console.WriteLine(strStyleName);
        paragraph.ListFormat.ListLevelNumber = ListLevelNumber;
    }
}
doc.FirstSection.AppendContent(docInclude.FirstSection);
doc.Save(MyDir + "17.4.docx");

Hi Tahir Manzoor,

Thanks for your quick response. I will check & update status.

Thanks & Regards,
Mani.

Hi Tahir Manzoor,

I have implemented your inputs. Now I got the exact output in word. But in PDF, the list(bullet) symbol is not shown properly. I have attached the documents.

Another Ques: How to restart the ‘List’ number in ‘Document’ level?

Could you please suggest us?

Thanks & Regards,
Mani.

Hi Mani,

Thanks for your inquiry. We suggest you please upgrade to the latest version of Aspose.Words for .NET 17.4. Please use following modified code example to get the desired output in PDF.

Document doc = new Document(MyDir + "Template.doc");
Document docInclude = new Document(MyDir + "Input_Html.htm");
foreach (Paragraph paragraph in docInclude.GetChildNodes(NodeType.Paragraph, true))
{
    string strStyleName = paragraph.ParagraphFormat.StyleName;
    if (paragraph.IsListItem)
    {
        int ListLevelNumber = paragraph.ListFormat.ListLevelNumber;
        List list = paragraph.ListFormat.List;
        paragraph.ParagraphFormat.ClearFormatting();
        paragraph.ParagraphBreakFont.ClearFormatting();
        foreach (Run run in paragraph.Runs)
        {
            run.Font.ClearFormatting();
        }
        paragraph.ParagraphFormat.StyleName = strStyleName;
        Console.WriteLine(strStyleName);
        paragraph.ListFormat.List = list;
        paragraph.ListFormat.ListLevelNumber = ListLevelNumber;
    }
}
doc.FirstSection.AppendContent(docInclude.FirstSection);
doc.Save(MyDir + "17.4.pdf");

manig:
Another Ques: How to restart the ‘List’ number in ‘Document’ level?

Please use ListLevel.StartAt property to set the starting number for this list level. In this case, you need to clone the current list and set it for desired paragraphs. ListCollection.addCopy method creates a new list by copying the specified list and adding it to the collection of lists in the document. You may use ListLevel.RestartAfterLevel property to set the list level that must appear before the specified list level restarts numbering.

Hi Tahir Manzoor,

Thanks for your quick response.I will update the latest version(17.4). I will check & update status.

Thanks & Regards,
Mani.

Hi Tahir Manzoor,

I have updated the latest version(17.4). I have applied your modified code, now both output ‘LIST’ starting position is not good. I have attached the result document.

Thanks & Regards,
Mani.

Hi Mani,

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-15283. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi Tahir Manzoor,

Thanks for your response, I will expect soon.

Thanks & Regards,
Mani.

Hi Tahir Manzoor,

Thanks for your support.
If any updation done please inform…Thanks…

@rengnext,

Thanks for your inquiry. Currently, your issue is under analysis phase. Once our product team completes the analysis of this issue, we will then be able to provide you the estimate. Thanks for your patience and understanding.