PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Apr 16, 2024 5:24 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: How to add bullet point
PostPosted: Tue Dec 16, 2008 2:47 pm 
Offline

Joined: Tue Dec 16, 2008 2:44 pm
Posts: 1
How do I add a bullet point to a paragraph? An example code will be greatly appreciated. I search for forum for example and came up with none.


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 31, 2009 9:25 pm 
Offline

Joined: Tue Feb 24, 2009 5:56 pm
Posts: 4
max1001 wrote:
How do I add a bullet point to a paragraph? An example code will be greatly appreciated. I search for forum for example and came up with none.


I'm no expert, so this may not be the only answer, but I have added bullet points as part of the text... For example:

Code:
AddParagraph(sec, "• Other Comments", true, ParagraphAlignment.Left, 12);


(Note that the 'AddParagraph' function is a separate method, not a PDFSharp/MigraDoc function, but it's steps are trivial. Also, it appears that the character is mangled by this forum... it really is a bullet. You should be able to insert these characters in your editor if you are using a decent one.)

-mdb


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 31, 2009 11:17 pm 
Offline

Joined: Tue Feb 24, 2009 5:56 pm
Posts: 4
max1001 wrote:
How do I add a bullet point to a paragraph? An example code will be greatly appreciated. I search for forum for example and came up with none.


If you are using MigraDoc, I now see you can also do something like:

Code:
Paragraph p = sec.AddParagraph();
p.AddCharacter(SymbolName.Bullet);


Top
 Profile  
Reply with quote  
PostPosted: Wed Apr 01, 2009 7:39 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
max1001 wrote:
How do I add a bullet point to a paragraph? An example code will be greatly appreciated. I search for forum for example and came up with none.


Here's a sample:
Code:
ListInfo listinfo = new ListInfo();
listinfo.ContinuePreviousList = false;//true for following entries
listinfo.ListType = ListType.BulletList1;
Paragraph paragraph = Document.LastSection.AddParagraph(text);
paragraph.Style = "MyListStyle"; // optional
paragraph.Format.ListInfo = listinfo;


This way you get a "real bullet list" if you create an RTF file.
The method described by fuzzylintman works, too.
If you need PDF files, either method can be used.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Feb 26, 2010 3:57 pm 
Offline

Joined: Fri Feb 26, 2010 3:50 pm
Posts: 4
Thanks for the sample Thomas, but could you elaborate on how to create multiple bullets in the list?

I would have assumed you could have re-used ListInfo objects, but it appears you have to create a new one for each paragraph/bullet - is that right?

I would have expected some sort of logic like "start list", "add member", "add member", "add member" then "end list". Or use line breaks within a single paragraph to differentiate bulleted items.

Could you post code showing how to create a longer bulleted list using a loop?

Thanks, TJ


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 01, 2010 9:05 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
TimJohnston wrote:
I would have assumed you could have re-used ListInfo objects, but it appears you have to create a new one for each paragraph/bullet - is that right?

MigraDoc manages the list - you mark the paragraphs as list members.

You use
Code:
listinfo.ContinuePreviousList = false;

for the first entry in a list and
Code:
listinfo.ContinuePreviousList = true;//

for subsequent entries in the same list (makes a big difference for numbered lists).

Here are two helper routines I use:
Code:
bool continueList;

protected void DefineList()
{
  continueList = false;
}

protected void AddToList(TemplateTable tt, string text)
{
  ListInfo listinfo = new ListInfo();
  listinfo.ContinuePreviousList = continueList;
  listinfo.ListType = ListType.BulletList1;
  Paragraph paragraph = Document.LastSection.AddParagraph(text);
  paragraph.Style = tt.GetBulletListStyle(Document);
  paragraph.Format.ListInfo = listinfo;
  continueList = true;
}

TemplateTable provides formatting info and is not relevant here.
DefineList() only sets a member variable so next time a new list will be created.
AddToList() is called for each entry.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 05, 2010 6:46 am 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 340
Here's a sample (a few lines added to the HelloWorld sample):
Code:
// 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 = "April|May|Summer|Wednesdays".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 above in this thread).

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 78 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group