Hi,
Before saving the final document, I would like programmatically increase spacing before and after each paragraph.
Could you please provide me with sample code.
Thank you.
Hi,
Before saving the final document, I would like programmatically increase spacing before and after each paragraph.
Could you please provide me with sample code.
Thank you.
Hi Godson,
Thanks for your inquiry. Sure, you can achieve this by using the following code snippet:
foreach (Paragraph p in doc.GetChildNodes(NodeType.Paragraph, true))
{
p.ParagraphFormat.SpaceBefore = 20;
p.ParagraphFormat.SpaceAfter = 20;
}
I hope, this will help.
Best Regards,
Thank you Awais,
And what if I want implement this code but starting from specific section of the document (for example I do not want to update paragraph format in the first four sections).
Thanks.
Hi Awais,
I did try your sample:
foreach (Paragraph p in doc.GetChildNodes(NodeType.Paragraph, true))
{
p.ParagraphFormat.SpaceBefore = 6;
p.ParagraphFormat.SpaceAfter = 3;
}
And it is working properly. Thank you.
Now I can see paragraph format(spacing) is the same for all lines(normals and headers).
But I have in the final document a lot of lines with ‘Heading 2’ format.
In this case I need different space before and after for ‘Heading 2’ lines than for normal lines.
(for example: .SpaceBefore = 12; .SpaceAfter = 12;)
I need at least two different paragraph formats in the same time.
Could you please provide me with sample code.
Thank you.
Hi Godson,
Thanks for your inquiry. In this case, you can try something like below:
int i = 0;
foreach (Section sec in doc.Sections)
{
// Skip first four sections
if (i > 3)
{
foreach (Paragraph p in sec.GetChildNodes(NodeType.Paragraph, true))
{
if (p.ParagraphFormat.StyleIdentifier == StyleIdentifier.Heading2)
{
p.ParagraphFormat.SpaceBefore = 12;
p.ParagraphFormat.SpaceAfter = 12;
}
else
{
p.ParagraphFormat.SpaceBefore = 6;
p.ParagraphFormat.SpaceAfter = 3;
}
}
}
i++;
}
I hope, this will help.
Best Regards,
Thank you for help.
Best regards.
Hi Awais,
For each page in the bottom in the right end corner I need to insert some text.
I do not want to insert this text in the footer.
I am trying like this:
builder.InsertField(@"MERGEFIELD TextData \* MERGEFORMAT", someText);
But how to move to bottom and right corner of the page.
Do you have some sample.
Thank you.
Is it possible to insert somerField in the footer?
Thank you.
Hi,
Thanks for your inquiry. Please note that MS Word Document is a flow document i.e. it does not contain any information about its layout into pages. So there is no direct way to determine where page starts or ends using Aspose.Words and hence you can’t easily insert some text at the end of each page of your document. Secondly, you can use DocumentBuilder.MoveToHeaderFooter method and the following code to be able to insert a field in the footer:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
builder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Right;
builder.InsertField(@"MERGEFIELD MyFieldName * MERGEFORMAT");
doc.Save(@"c:\temp\out.docx");
I hope, this will help.
Best Regards,