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

Free Support Forum - aspose.com

Alignment of Table created using HTML tags in a Paragraph

Hello,

We are using Aspose.Words 9.0 in our application.
We are using documentbuilder.InsertHTML() method to insert all types of texts in word document.
We are facing problem when a piece of text is inserted using HTML tags having Table inside the tags.
Problem is with the alignment of this table with rest of the text.
Following sample code demonstrates how paragraphs are created,

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);

//set the page set-up
PageSetup pageSetup = documentBuilder.CurrentSection.PageSetup;
pageSetup.PaperSize = PaperSize.A4; //set the page size.

string filePath = @“D:\Projects\CreateMultiCandidateMOO\CreateMultiCandidateMOO\bin\Debug\Rule Content.txt”;

string strHTMLText = File.ReadAllText(filePath);

documentBuilder.Font.Name = “Arial”;

documentBuilder.ParagraphFormat.LeftIndent = 20;
documentBuilder.InsertHtml(“Line One of this document”);
documentBuilder.InsertBreak(BreakType.LineBreak);
documentBuilder.ParagraphFormat.ClearFormatting();

documentBuilder.ParagraphFormat.LeftIndent = 20;
documentBuilder.InsertHtml(“Second Line of this document”);
documentBuilder.InsertBreak(BreakType.LineBreak);
documentBuilder.ParagraphFormat.ClearFormatting();

documentBuilder.ParagraphFormat.LeftIndent = 20;
documentBuilder.InsertHtml(strHTMLText);
documentBuilder.ParagraphFormat.ClearFormatting();

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

Attached is the output of this sample code. If you take a look at document you will find first three line of text have come with left indent = 0.28" while table displays left indent = 0

HTML text contents are also attached for your reference.

Do let us know why this is happening.

Regards,
Dwarika

Hi

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

Thanks for your inquiry. ParagraphFormat.LeftIndent will not have and should not have any effect on Table indent. The only way to specify indent of table, I can suggest you at the moment is post-processing your document after inserting HTML.

Best regards.