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

Free Support Forum - aspose.com

Set paragraph font size

After adding a table to a document, I am add a paragraph.how can I set the font size for this paragraph?

private Document _doc;
private Table tableNode;

using (MemoryStream ms = new MemoryStream(ScenarioResources.Prepaid_Minute_Plan_Template))
Document templateDoc = new Document(ms, new LoadOptions { LoadFormat = LoadFormat.Docx });
Table sourceTable = GetSourceTable(templateDoc.LastSection.Body);

NodeImporter importer = new NodeImporter(templateDoc, _doc, ImportFormatMode.KeepSourceFormatting);
Section lastSection = _doc.LastSection;
tableNode = importer.ImportNode(sourceTable, true) as Table;

if (tableNode != null)
Row headerRow0 = tableNode.Rows[0].Clone(true) as Row;
Row headerRow1 = tableNode.Rows[1].Clone(true) as Row;
Row headerRow2 = tableNode.Rows[2].Clone(true) as Row;
Row itemRow = tableNode.Rows[3].Clone(true) as Row;
string definition = "This has to be BOLD";

Paragraph paragraph = new Paragraph(_doc);
paragraph.AppendChild(new Run(_doc, definition));
lastSection.Body.AppendChild(new Paragraph(_doc));
Also how can I set part of the text in the paragraph to bold?

Hi Ruchi,

Thanks for your inquiry. Please note that formatting is applied on a few different levels. For example, let’s consider formatting of simple text. Text in documents is represented by Run element and a Run can only be a child of a Paragraph. You can apply formatting

1) to Run nodes by using Character Styles e.g. a Glyph Style,
2) to the parent of those Run nodes i.e. a Paragraph node (possibly via paragraph Styles)
3) you can also apply direct formatting to Run nodes by using Run attributes (Font). In this case the Run will inherit formatting of Paragraph Style, a Glyph Style and then direct formatting.

Please check the following code snippet. Hope this helps you.

Document doc = new Document(MyDir + “in.docx”);<o:p></o:p>

Paragraph paragraph = (Paragraph)doc.GetChild(NodeType.Paragraph, 0, true);

//Change the size of paragraph

paragraph.ParagraphFormat.Style.Font.Size = 11.0;

//Change the size and bold formatting of Run node (part of paragraph's text)

paragraph.Runs[0].Font.Size = 14.0;

paragraph.Runs[0].Font.Bold = true;