We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Problem in Aspose Word for HTML bulleted text - Adding extra space in the end

Hi Alexey,

Thanks for your quick support & reply.

We are using Aspose Word version 7.0.0.0.

We are facing one problem while creating a document in Aspose Word for bulleted text.

There are two approach for creating bulleted tags

1> Using Aspose API.

2> Using InsertHTML method where text contain HTML tags for Bullets (

    -
  • tag combination.)

    We are interested in 2 nd approach.

    But while inserting the HTML Bulleted tags there is an extra space added at the end of last bulleted text ( please refer the attached image "Error_Image1.PNG" for furtehr reference).

    We found that the pargraph setting for last bulleted text contain "Spacing After" property set as "Auto" by default.( please refer the attached image "Error_Image2.PNG" for further reference.)

    Please refer the attched "Bulleted.doc" sample word document.

    The sample code used to create this document is as follows.

    private void button30_Click(object sender, EventArgs e)

    {

    Document doc = new Document();

    DocumentBuilder documentBuilder = new DocumentBuilder(doc);

    XmlDocument XmlDoc = new XmlDocument();

    string path = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

    Aspose.Words.License lic = new Aspose.Words.License();

    lic.SetLicense(path + @"\Aspose.Total.lic");

    Aspose.Pdf.License lic1 = new Aspose.Pdf.License();

    lic1.SetLicense(path + @"\Aspose.Total.lic");

    documentBuilder.InsertHtml("By using insert HTML Method:-");

    string str = "

    • A Verified result indicates that the original Ability Test score can be used with confidence.
    • A Not Verified result indicates that the original Ability Test score could not be verified. Further action is recommended before using the original Ability Test score for decision-making.
    ";

    documentBuilder.InsertHtml(str);

    doc.Save("OK.doc");

    StartWord("OK.doc");

    }

    But as far as origional fucntionality of MS-Word concern "no extra space get added after last bulleted text".

    1>Why this Extra Space is getting added after the last bulleted text?

    2> Is there is any way to remove that extra space?

    3> Will you please suggest us any kind of HTML combination which can avoid addition of the extra space?

    Waiting for your reply.......!!!!!!!

    Thanks & Regards,

    Dwarika

Hi Dwarika,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I managed to reproduce the problem on my side. The problem occurs because automatic spacing is applied to the inserted paragraphs. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

As a workaround, you can just reset auto spacing of paragraphs. Please see the following code example:

// Loop through all paragraphs and reset auto spacing.

NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);

foreach (Paragraph paragraph in paragraphs)

{

paragraph.ParagraphFormat.SpaceAfterAuto = false;

paragraph.ParagraphFormat.SpaceAfter = 0;

}

// Save output document.

doc.Save("out.doc");

Hope this helps.

Best regards,

Hello,


We tried out with the work around you have provided, but the problem still persists.

We are getting the same output that we have attached to demonstrate you about this scenario.

Is there any other way to remove this extra space after bullet point.

Regards,
Dwarika

Hello

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I tried using the suggested workaround with your document, and it works fine on my side. I attached the output document produced on my side. Please try using the latest version of Aspose.Words (9.0.0).

Best regards,

Hello,


forgot to mention in my post that the testing for bullet points is carried with Aspose.Words 9.0

and still this is not working with sample code.

Regards,
Dwarika

Hello

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. Please make sure that you are using the latest version. Also could you please try creating a simple console application using the following code and the document from your first post?

Document doc = new Document("Bulleted.doc");

// Loop through all paragraphs and reset auto spacing.

NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);

foreach (Paragraph paragraph in paragraphs)

{

paragraph.ParagraphFormat.SpaceAfterAuto = false;

paragraph.ParagraphFormat.SpaceAfter = 0;

}

// Save output document.

doc.Save("out.doc");

After running this application, please try opening the out.doc and you will see the result like on the attached screenshot. It means that the workaround works fine.

Also did you check the out.doc from my previous post? I used the suggested workaround to get this result.

Best regards,

Hello Andrey,


In your post you are loading previously created document by using instance of document object, which is not the case in our code base. Therefore fetching all paragraphs using NodeCollection is also not possible.

Though we tried using the piece of code you have supplied,

paragraph.ParagraphFormat.SpaceAfterAuto = false;<o:p></o:p>

paragraph.ParagraphFormat.SpaceAfter = 0;


which is also not working with Aspose 9.0.0.0.


Do let us know still is there any workaround that we can try?


Following code is modified with your workaround but still this is not working for us.


Document doc = new Document();

DocumentBuilder documentBuilder = new DocumentBuilder(doc);

XmlDocument XmlDoc = new XmlDocument();


string path = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);


Aspose.Words.License lic = new Aspose.Words.License();

lic.SetLicense(path + @"\Aspose.Total.lic");

Aspose.Pdf.License lic1 = new Aspose.Pdf.License();

lic1.SetLicense(path + @"\Aspose.Total.lic");


documentBuilder.ParagraphFormat.SpaceAfterAuto = false;

documentBuilder.ParagraphFormat.SpaceAfter = 0;


documentBuilder.InsertHtml("By using insert HTML Method:- ");

string str = “

  • A Verified result indicates that the original Ability Test score can be used with confidence.
  • A Not Verified result indicates that the original Ability Test score could not be verified. Further action is recommended before using the original Ability Test score for decision-making.
”;

documentBuilder.InsertHtml(str);

documentBuilder.ParagraphFormat.SpaceAfterAuto = false;

documentBuilder.ParagraphFormat.SpaceAfter = 0;


doc.Save(“OK.doc”);

StartWord(“OK.doc”);


Attached is the output after adding two lines of code (highlighted) for your reference.


Regards,

Dwarika

Hi Dwarika,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. But actually, you did not implemented the workaround suggested by Andrey. That is why you still get the same result. Andrey suggested to loop through all paragraphs in the document and resetting auto-spacing after inserting HTML. Actually you should do this just before saving the document.

I modified your code:

Document doc = new Document();

DocumentBuilder documentBuilder = new DocumentBuilder(doc);

XmlDocument XmlDoc = new XmlDocument();

string path = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

Aspose.Words.License lic = new Aspose.Words.License();

lic.SetLicense(path + @"\Aspose.Total.lic");

Aspose.Pdf.License lic1 = new Aspose.Pdf.License();

lic1.SetLicense(path + @"\Aspose.Total.lic");

documentBuilder.InsertHtml("By using insert HTML Method:- ");

string str = "

  • A Verified result indicates that the original Ability Test score can be used with confidence.
  • A Not Verified result indicates that the original Ability Test score could not be verified. Further action is recommended before using the original Ability Test score for decision-making.
";

documentBuilder.InsertHtml(str);

// Just before saving you shoudl use the suggested code.

// Loop through all paragraphs and reset auto spacing.

NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);

foreach (Paragraph paragraph in paragraphs)

{

paragraph.ParagraphFormat.SpaceAfterAuto = false;

paragraph.ParagraphFormat.SpaceAfter = 0;

}

doc.Save("OK.doc");

StartWord("OK.doc");

Best regards,

Hello Alexey,


I tried the way you are suggested. It is working as you have explained.

With the above solution all the paragraphs will have spaceafter = 0 and spaceafterauto = false.

But the requirement is a document having 5 paragraphs, individual paragraph will have different setting for spaceafter and if we run this code just before saving the document then all the paragraphs will have spaceafter = 0 rather they should show what is set individual on them.

attached is the output document. ok.doc is how the requirement while notok.doc is how it is generating after doing code changes.

Below is the code how we need paragraph formatting on each paraghaph

Document doc = new Document();
DocumentBuilder documentBuilder = new DocumentBuilder(doc);
XmlDocument XmlDoc = new XmlDocument();

string path = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

Aspose.Words.License lic = new Aspose.Words.License();
lic.SetLicense(path + @"\Aspose.Total.lic");
Aspose.Pdf.License lic1 = new Aspose.Pdf.License();
lic1.SetLicense(path + @"\Aspose.Total.lic");

documentBuilder.InsertHtml(“By using insert HTML Method:-”);
string str = “
  • A Verified result indicates that the original Ability Test score can be used with confidence.
  • A Not Verified result indicates that the original Ability Test score could not be verified. Further action is recommended before using the original Ability Test score for decision-making.
”;
documentBuilder.InsertHtml(str);

documentBuilder.InsertBreak(BreakType.LineBreak);

documentBuilder.ParagraphFormat.SpaceAfter = 20;

documentBuilder.InsertHtml(“After setting the paragraphs:-”);
str = “
  • A Verified result indicates that the original Ability Test score can be used with confidence.
  • A Not Verified result indicates that the original Ability Test score could not be verified. Further action is recommended before using the original Ability Test score for decision-making.
”;
documentBuilder.InsertHtml(str);

// Just before saving you shoudl use the suggested code.
// Loop through all paragraphs and reset auto spacing.
NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);
foreach (Paragraph paragraph in paragraphs)
{
paragraph.ParagraphFormat.SpaceAfterAuto = false;
paragraph.ParagraphFormat.SpaceAfter = 0;
}

doc.Save(“OK.doc”);
StartWord(“OK.doc”);

The highlighted line of code does have impact after we set the following properties

paragraph.ParagraphFormat.SpaceAfterAuto = false;
paragraph.ParagraphFormat.SpaceAfter = 0;

while we need each paragraph with distinct paragraph formatting.

Best Regards,
Dwarika


Hi Dwarika,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. As I can see, you get OK.doc just by inserting HTML into the document (i.e. without any workarounds). So the reasonable question will be – What is wrong with this document?

Maybe you mean line break at the end of the first list (see the attached screenshot). If so, then just do not insert it in your code.

documentBuilder.InsertHtml("By using insert HTML Method:-");

string str = "

  • A Verified result indicates that the original Ability Test score can be used with confidence.
  • A Not Verified result indicates that the original Ability Test score could not be verified. Further action is recommended before using the original Ability Test score for decision-making.
";

documentBuilder.InsertHtml(str);

documentBuilder.InsertBreak(BreakType.LineBreak);

documentBuilder.ParagraphFormat.SpaceAfter = 20;

documentBuilder.InsertHtml("After setting the paragraphs:-");

str = "

  • A Verified result indicates that the original Ability Test score can be used with confidence.
  • A Not Verified result indicates that the original Ability Test score could not be verified. Further action is recommended before using the original Ability Test score for decision-making.
";

documentBuilder.InsertHtml(str);

Best regards.

Hello Alexey,


That line break is needed but we would like to get rid of extra line break which is inserted due to bullet points using list tag of HTML

Attached file does not have line break but still shows extra space after bullet list.
It is marked with red outlined box.

Regards,
Dwarika

Hello

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. Unfortunately, I cannot suggest you any other way to work this problem around at the moment. You should just wait for the fix of the original issue. You will be notified as soon as it is fixed.

Best regards,

Hello,

We tried with the work around provided by as using listItems and revisiting the paragraph to set the margin. For some extent it is working.

The problem is the bullets appearing on the page when the left margin is set as 30, 45 and 70.

Attached are the various output files for your consideration.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Problems are as follows,

  1. when left margin is set as 30 the bullets are very near to the text.
  2. when left margin is set as 45 or 70 bullets are not with the spacing as having margin as 30.
  3. Also the first bullet appears as bold and big in size as compared with others in the same document.

Regards,

Dwarika

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I think, You can try playing with ListLevel.NumberPosition, ListLevel.TabPosition, ListLevel.TextPosition to configure each level of your list (see the attached screenshot). Please see the following link for more information:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/aspose.words.lists.listlevel.html

Also, I think, the information provide in the following thread could be useful for you.

Best regards.

Hello Alexey,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I have gone through both the links you have provided and have following doubt,

There are settings like

level1.NumberPosition = -36;
level1.TextPosition = 144;
level1.TabPosition = 144;

-36, 144 and 144 are these values hardcoded? I mean if we want to set these numbers as per the margin setting what should be the value?

I am using following code in my sample application to set above parameters,

string path = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

//Initialize Aspose license. Aspose Word version 9.0.0.0

Aspose.Words.License lic = new Aspose.Words.License();

lic.SetLicense(path + @"\Aspose.Total.lic");

Aspose.Pdf.License lic1 = new Aspose.Pdf.License();

lic1.SetLicense(path + @"\Aspose.Total.lic");

Document doc = new Document();

DocumentBuilder documentBuilder = new DocumentBuilder(doc);

Run run;

Aspose.Words.Font font;

//set the page set-up

PageSetup pageSetup = documentBuilder.CurrentSection.PageSetup;

pageSetup.PaperSize = PaperSize.A4; //set the page size.

pageSetup.LeftMargin = 50;

documentBuilder.ParagraphFormat.ClearFormatting();

//set font

run = new Run(doc);

font = run.Font;

documentBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left;

font.Name = "Arial Unicode MS";

font.Size = 11;

font.Italic = false;

string strBullet = "Paragraph for bullet points:

  • First bullet point
  • Second bullet point
  • Third bullet point
  • <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />Forth bullet point
";

Paragraph currNode = documentBuilder.CurrentParagraph;

documentBuilder.InsertHtml("Document to test bullets in a paragraph");

documentBuilder.InsertBreak(BreakType.LineBreak);

documentBuilder.InsertHtml("Paragraph for bullet points:
"
);

documentBuilder.InsertHtml(strBullet);

//documentBuilder.InsertHtml("Text after bullet points");

do

{

if (currNode.NodeType == NodeType.Paragraph)

{

Paragraph currentParagraph = (Paragraph)currNode;

currNode.ParagraphFormat.LeftIndent = 50;

if (currNode.IsListItem)

{

currNode.ListFormat.ListLevel.NumberPosition = 50;

currNode.ListFormat.ListLevel.TextPosition = 50;

currNode.ListFormat.ListLevel.TabPosition = 50;

}

// move to next node

currNode = (Paragraph)currNode.NextSibling;

}

} while (currNode != null && !currNode.Equals(documentBuilder.CurrentParagraph));

// Loop through all paragraphs and reset auto spacing.

NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);

foreach (Paragraph paragraph in paragraphs)

{

paragraph.ParagraphFormat.SpaceAfterAuto = false;

paragraph.ParagraphFormat.SpaceAfter = 0;

}

documentBuilder.InsertHtml("Text after bullet points");

doc.Save("HTML_Bullets_12Oct2010.doc");

StartWord("HTML_Bullets_12Oct2010.doc");

Bulleted list should use the margin set for the page (in this case I am using left margin as 50 & therefore I have set NumberPosition, TextPosition and TabPosition as 50.

Do let me know what is wrong with the above code and how do we rectify the spacing between the bullet and the text when the margin value is changed.

Also whether we need to use all the three (NumberPosition, TextPosition and TabPosition) to set bulletted text?

Regards,

Dwarika

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Note: Indent of paragraph is distance from left margin of page to text, but not distance from left edge of page to text.

Please try using this code:

Document doc = new Document();

DocumentBuilder documentBuilder = new DocumentBuilder(doc);

Run run;

Aspose.Words.Font font;

//set the page set-up

PageSetup pageSetup = documentBuilder.CurrentSection.PageSetup;

pageSetup.PaperSize = PaperSize.A4; //set the page size.

pageSetup.LeftMargin = 50;

documentBuilder.ParagraphFormat.ClearFormatting();

//set font

run = new Run(doc);

font = run.Font;

documentBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left;

font.Name = "Arial Unicode MS";

font.Size = 11;

font.Italic = false;

string strBullet = "Paragraph for bullet points:

  • First bullet point
  • Second bullet point
  • Third bullet point
  • Forth bullet point
";

Paragraph currNode = documentBuilder.CurrentParagraph;

documentBuilder.InsertHtml("Document to test bullets in a paragraph");

documentBuilder.InsertBreak(BreakType.LineBreak);

documentBuilder.InsertHtml("Paragraph for bullet points:
"
);

documentBuilder.InsertHtml(strBullet);

//documentBuilder.InsertHtml("Text after bullet points");

do

{

if (currNode.NodeType == NodeType.Paragraph)

{

Paragraph currentParagraph = (Paragraph)currNode;

if (currNode.IsListItem)

{

currNode.ListFormat.ListLevel.NumberPosition = 0;

currNode.ListFormat.ListLevel.TextPosition = 30;

currNode.ListFormat.ListLevel.TabPosition = 30;

}

// move to next node

currNode = (Paragraph)currNode.NextSibling;

}

} while (currNode != null && !currNode.Equals(documentBuilder.CurrentParagraph));

// Loop through all paragraphs and reset auto spacing.

NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);

foreach (Paragraph paragraph in paragraphs)

{

paragraph.ParagraphFormat.SpaceAfterAuto = false;

paragraph.ParagraphFormat.SpaceAfter = 0;

}

documentBuilder.InsertHtml("Text after bullet points");

doc.Save(@"Test001\out.doc");

Best regards,

Hello Alexey,

Thanks very much for inputs. I tried using setting currNode.ListFormat.ListLevel.NumberPosition = 0;

but below two properties i am using the value of Page left margin as this is the system requirement.

currNode.ListFormat.ListLevel.TextPosition = 50;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

currNode.ListFormat.ListLevel.TabPosition = 50;

but still it is not working.Attached is the output after doing above change.

What we want is bullet point should start right below the title "

Test Bullet" and there should not be any gap / space between the bullet and the text.

I hope you have understood my problem.

Do let me know if there is any other workaround.

Regards,

Dwarika

Hi Dwarika,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. Could you please also share your HTML here? I tested with code I posted in my previous post and the generated document looks fine. Have you tried with the code I posted?

Best regards,

Hello Alexey,

I have used the code that you have provided in the earlier post. Because of that code sample only bullets are working as per requirement to some extent.

But like the problems i have listed down in my earlier post are not yet resolved.

Following strings we are using to display bullets in word output

1.

  • This is step 1

  • This is step 2

  • This is step 3

2. This is a bulleted text:

  • This is step 1

  • This is step 2

  • This is step 3

Regards,

Dwarika

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. As I can see, HTML is the same as I used in the code example. I attached my output document. As you can see, it looks correct.

Best regards,