Aspose delete double spaces

Simple test

String s1 = "<p style=\"margin-top:12pt; margin-bottom:0pt; line-height:115%; widows:0; orphans:0; font-size:11pt\">\"font-family:Arial; font-weight:bold\">Customer:\"font-family:Arial\"> </p>";
String s2 = "<p style=\"margin-top:12pt; margin-bottom:0pt; line-height:115%; widows:0; orphans:0; font-size:11pt\">\"font-family:Arial; font-weight:bold\">Customer:\"font-family:Arial\">  Hello  Sign</p>";

DocumentBuilder builder1 = new DocumentBuilder();
DocumentBuilder builder2 = new DocumentBuilder();
builder1.insertHtml(s1);
builder2.insertHtml(s2);
Document d1 = builder1.getDocument();
Document d2 = builder2.getDocument();
d1.compare(d2, "fff", new Date());
String f = d1.toString(SaveFormat.HTML);
System.out.println(f);

and in result :

"<p style=\"margin-top:12pt; margin-bottom:0pt; line-height:115%; widows:0; orphans:0; font-size:11pt\">\"font-family:Arial; font-weight:bold\">Customer:\"font-family:Arial\"> <ins>\"font-family:Arial\">Hello Sign</ins></p>"

Before “Hello Sing” was 2 spaces, after “Customer” wa" 1 space, after compare before “Hello Sing” only 1 space. Between “Hello Sing” double space deleted to.

Hi Mike,

Thanks for your inquiry.

Please note that Aspose.Words mimics the same behavior as MS Word does. If you load your html document in MS Word, you notice only once space. If you open the input html in browser, you will see only once space.

Please let us know if you have any more queries.

Hi, yes it’s true, but how solve my problem.

Document d1 = new Document("c:\\1\\5.docx");
d1.save("c:\\1\\5.html", SaveFormat.HTML);
DocumentBuilder builder1 = new DocumentBuilder();
String st = FileUtils.readFileToString(new File("c:\\1\\5.html"));
builder1.insertHtml(st);
Document r = builder1.getDocument();
r.save("c:\\1\\6.docx", SaveFormat.DOCX);
r.save("c:\\1\\6.html", SaveFormat.HTML);

if you compare “5.docx” with “6.docx”, you will see revision http://joxi.ru/52aNNzPF404EaABut document doesn’t change.

Hi Mike,
Thanks for your inquiry. In your case, we suggest you please replace non breaking space with simple space before saving the final document. Hope this helps you.

Document r = builder1.getDocument();
r.getRange().replace(ControlChar.NON_BREAKING_SPACE, " ", new FindReplaceOptions());
r.save(MyDir + "6.docx", SaveFormat.DOCX);
r.save(MyDir + "6.html", SaveFormat.HTML);