@niktv
Thanks for your inquiry.
Please note that TextBuilder.AppendParagraph()
and page.Paragraphs.Add()
, both are used to add text inside the PDF, depending upon the scenario. TextBuilder
acts like a container which contains its own collection of paragraphs - whereas page.Paragraphs.Add()
method, adds paragraph(s) in Paragraphs
collection of page.
However, using TextBuilder
and TextParagraph
approach, you may set properties (e.g Margins) of entire paragraph (inside TextBuilder
) which can have more than one TextFragments
in it. Whereas if you are adding different text fragments, which can have different properties from one another (e.g Margins, Style, Font, etc.), you may add them while using page.Paragraphs.Add()
method.
Furthermore, TextParagraph
is used to append lines within a paragraph, so each new call to AppendLine()
method, would add text in new line (Similar to AppendParagraph()
method of TextBuilder
class). Therefore, AppendText()
method of TextBuilder
class would append text to existing text.
Now concerning to your original requirement, it can be achieved by specifying margins of TextFragment
and adding it through page.Paragraphs.Add()
method. Please try using following code snippet, in order to add numbered bullets and its data accordingly inside PDF. For your reference, we have attached a sample out as well, generated by below code snippet.
Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
Page page = doc.Pages.Add();
TextFragment headingNumber = new TextFragment("4.");
headingNumber.IsInLineParagraph = true;
headingNumber.TextState.FontSize = 10;
headingNumber.TextState.FontStyle = FontStyles.Bold;
TextFragment headingFragment = new TextFragment("Lorem Ipsum:");
headingFragment.Margin = new MarginInfo(10, 10, 0, 0);
headingFragment.IsInLineParagraph = true;
headingFragment.TextState.FontSize = 10;
headingFragment.TextState.FontStyle = FontStyles.Bold;
page.Paragraphs.Add(headingNumber);
page.Paragraphs.Add(headingFragment);
TextFragment numberFragment = new TextFragment("4.1.");
numberFragment.Margin = new MarginInfo(10, 0, 0, 0);
// keep this fragment with next paragraph level object
numberFragment.IsKeptWithNext = true;
TextFragment dataFragment = new TextFragment("Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum");
// set margins to specify indenting and bullet formatting
dataFragment.Margin = new MarginInfo(30, 10, 0, 0);
dataFragment.IsInLineParagraph = true;
page.Paragraphs.Add(numberFragment);
page.Paragraphs.Add(dataFragment);
doc.Save(dataDir + "NumberedBullets.pdf");
NumberedBullets.pdf (2.7 KB)
As we have already logged an investigation ticket in our issue tracking system, so as soon as we receive some feedback from our product team, we will let you know. Please spare us little time.
We are sorry for the inconvenience.