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

Free Support Forum - aspose.com

How to write text at both of side of page


i want to write something at the footer by using DocumentBuilder api,
just like below picture:

text position

some of text at the left side and others at the right side,but all of them in one paragraph, is any way for this purpose?


thanks

Hi Pyntia,


Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. If you want to insert text left and right of the page in one paragraph, you need to add space inside the same paragraph.

You can also achieve your requirement by inserting a table with one row and two cells. Please check the following code example for your kind reference. Hope this helps you.

Document doc = new
Document();<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);

// We call this method to start building the table.

Table table = builder.StartTable();

builder.InsertCell();

builder.Write("Row 1, Cell 1 Content.");

// Build the second cell

builder.InsertCell();

builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;

builder.Write("Page ");

builder.InsertField("PAGE", "");

// Call the following method to end the row and start a new row.

builder.EndRow();

// Signal that we have finished building the table.

builder.EndTable();

doc.UpdateFields();

// Save the document to disk.

doc.Save(MyDir + "Out.docx");


hi, Tahir


thank you for sharing me this good idea.

but table element will show additional line break mark at each end of line.

i want to insert space inside the paragraph, but i cannot get the accurate width of the existed text. is any idea for this?

Hi Pyntia,


Thanks for your inquiry. There is no specific way to calculate the accurate width of existing text in a line and insert n number of spaces inside the same paragraph. This also depends on font size.

As a work around you can try using a fixed width font, such as Courier New. Using this font, you can calculate number of characters inside the same paragraph/line. Hope this helps you.

hi, Tahir


thank you very much. i will consider using table for instead.

Hi Pyntia,


Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.