Free Support Forum - aspose.com

InsertHTML containing <br /> inserts vertical tab (ascii character 11)

When calling the InsertHTML(string sText) method where sText contains some
tags, these appear to get inserted into the Word document as vertical tabs (ascii character 11). Ordinarily this would not cause a problem but since the text being inserted needs to be aligned using the "Justify" setting the vertical tab is not seen as a true end of line and consequently I end up with the last line, perhaps containing only 2 words, being stretched to fill the complete line.

Is there a way to tell aspose to deal with
's in a different manner (ie. use CR or LF characters)?

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

Thanks for your request. You are absolutely right
is represented as line break. As a workaround you can try using the following code.

html = html.Replace("
"
, "

");

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.InsertHtml(html);

doc.Save("out.doc");

I hope this could help.

Best regards.

Thanks for your prompt reply. The problem with using

is that I end up losing the ParagraphFormat settings I set just before calling InsertHTML (in particular Alignment, LeftIndent and FirstLineIndent). As a work-around I was thinking I could just replace character 11 with ControlChars.CRLF using the Range.Replace() method but I have read the issues relating to using control characters in this method.

Any suggestions you have would be greatly appreciated.

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

Thanks for your request. Please try using the following code snippet.

public void Test040()

{

Document doc = new Document(@"Test040\in.doc");

Regex regex = new Regex("\v");

doc.Range.Replace(regex, new ReplaceEvaluator(Replace040), false);

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

}

ReplaceAction Replace040(object sender, ReplaceEvaluatorArgs e)

{

//Get MatchNode

Run run1 = (Run)e.MatchNode;

//Create Run

Run run2 = new Run(e.MatchNode.Document);

//Get index of match value

int index = run1.Text.LastIndexOf(e.Match.Value);

if (index > 0)

{

//Split text in match node

run2.Text = run1.Text.Substring(0, index);

run1.Text = run1.Text.Substring(index + e.Match.Value.Length);

}

else

{

run1.Text = run1.Text.Replace(e.Match.Value, "");

}

run1.ParentParagraph.InsertBefore(run2, run1);

DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document);

//Move to run1

builder.MoveTo(run1);

//Insert paragraph break

builder.Writeln();

return ReplaceAction.Skip;

}

I hope this could help you.

Best regards.

That has worked a treat Alexey. Thank you for your time.

It's a breath of fresh air to see such a well supported and monitored forum - full credit to the Aspose Team.