Hi,
I am trying to dynamically generate a horizontally centered paragraph but the TextState.HorizontalAlignment property fails. Could you help me with whats going wrong here.
Attaching below the code snippet and concerned pdf for the same.
Thanks
Certificate1d.pdf (428.5 KB)
TextFragmentAbsorber bodyFragmentAbsorber = new TextFragmentAbsorber("{this place is reserved for the body fields}");
doc.Pages.Accept(bodyFragmentAbsorber);
TextFragmentCollection bodyFragmentCollection = bodyFragmentAbsorber.TextFragments;
TextFragment bodyFragment = bodyFragmentCollection[1];
String value = "Some string that is dynamically generated with \n as a new line char and many \n in the content" ;
Char delimiter = '\n';
String[] substrings = value.Split(delimiter);
TextParagraph tempFragment = new TextParagraph();
foreach (var substring in substrings)
{
TextFragment updatedBodyFragment = new TextFragment(substring);
updatedBodyFragment.TextState.LineSpacing = 15;
updatedBodyFragment.TextState.FontSize = bodyFragment.TextState.FontSize;
updatedBodyFragment.TextState.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
updatedBodyFragment.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("Segoe UI");
updatedBodyFragment.TextState.ForegroundColor = bodyFragment.TextState.ForegroundColor;
tempFragment.AppendLine(updatedBodyFragment);
}
bodyFragment.Text = String.Empty;
tempFragment.Position = new Position(bodyFragment.Position.XIndent, bodyFragment.Position.YIndent - bodyFragment.TextState.FontSize - bodyFragment.TextState.LineSpacing);
TextBuilder bodyTextBuilder = new TextBuilder(bodyFragment.Page);
bodyTextBuilder.AppendParagraph(tempFragment);