Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you have a bulletted list in migradoc / pdfsharp

even after reading this forum post, its still quite confusing how to create a bulletted list using migradoc / pdfsharp. I basically want to display a list of items like this:

  • Dodge
  • Nissan
  • Ford
  • Chevy
like image 676
leora Avatar asked Oct 26 '10 15:10

leora


2 Answers

Here's a sample (a few lines added to the HelloWorld sample):

// Add some text to the paragraph
paragraph.AddFormattedText("Hello, World!", TextFormat.Italic);

// Add Bulletlist begin
Style style = document.AddStyle("MyBulletList", "Normal");
style.ParagraphFormat.LeftIndent = "0.5cm";
string[] items = "Dodge|Nissan|Ford|Chevy".Split('|');
for (int idx = 0; idx < items.Length; ++idx)
{
  ListInfo listinfo = new ListInfo();
  listinfo.ContinuePreviousList = idx > 0;
  listinfo.ListType = ListType.BulletList1;
  paragraph = section.AddParagraph(items[idx]);
  paragraph.Style = "MyBulletList";
  paragraph.Format.ListInfo = listinfo;
}
// Add Bulletlist end

return document;

I didn't use the AddToList method to have it all in one place. In a real application I'd use that method (it's a user-defined method, code given in this thread).

like image 151
I liked the old Stack Overflow Avatar answered Oct 06 '22 00:10

I liked the old Stack Overflow


A little bit more concise than the above answer:

var document = new Document();

var style = document.AddStyle("BulletList", "Normal");
style.ParagraphFormat.LeftIndent = "0.5cm";
style.ParagraphFormat.ListInfo = new ListInfo
{
    ContinuePreviousList = true,
    ListType = ListType.BulletList1
};

var section = document.AddSection();
section.AddParagraph("Bullet 1", "BulletList");
section.AddParagraph("Bullet 2", "BulletList");

Style is only created once, including listinfo, and can be re-used everywhere.

like image 42
Robin van der Knaap Avatar answered Oct 05 '22 22:10

Robin van der Knaap