SharpLeaf Tutorials > Text Flow Tutorials > Flowing Paragraphs

Flowing Paragraphs

The most straightforward way to flow text into a SharpLeaf document is to attach ParagraphStyles to text paragraphs.

   page = new PageLayout(PaperSize.Landscape(PaperSize.A5));
   page.Add(new Frame("Main",36,36,-36,-36));  // Half-inch margin all around
   layout = new DocumentLayout(page);

   body = new ParagraphStyle();
   body.Font = new FontType("Times",12);
   body.IndentFirst = 36;
   body.SpaceAfter = -1;  // Equivalent of one empty line of text

   bullet = body.Clone();  // Take deep copy as of now
   bullet.SpaceBetween = false;  // No space between bullet list items
   bullet.SetBullet("{1}.");  // Use numbered bullets
   bullet.BulletIndent = body.IndentFirst;  // Use same indent for bullets
   bullet.IndentFirst = 0;  // Unset the IndentFirst inherited from body

   title = new ParagraphStyle();
   title.Font = new FontType("Garamond",15,FontStyle.Bold,Color.Navy);
   title.IndentLeft = body.IndentFirst;  // Use same indent for titles
   title.SpaceBefore = -1;  // Leave room before a title - unless at top of frame
   title.SpaceAfter = -1;  // Leave room after a title
   title.BookmarkLevel = 1;  // Automatically bookmark titles at top level

   lf = new SharpLeaf(layout);

   para = "Here's a dummy paragraph of text. As the qualifier suggests its content is "+
            "not particularly interesting, but it still reaches its goal of being long "+
            "enough to take up more than one line.";
   paras = new string[]{para,para};
   list = new string[]{"First item on list","Another item here","And a last one there"};

  // Flow paragraphs with their styles
   lf.AddParagraphs("First title",title);
   lf.AddParagraphs(paras,body);
   lf.AddParagraphs(list,bullet);
   lf.AddParagraphs(para,body);
   lf.AddParagraphs("Second title",title);
   lf.AddParagraphs(paras,body);

See also ...

Text Flow Tutorials | Paragraph Glossary | SharpLeaf.Style Property | SharpLeaf.AddParagraphs Method | ParagraphStyle.Members


Send comments on this topic
© Dyalog Ltd 2021