6

In my Solution I am using bullet list in PDF files.

It looks something like that:

• Solcellepaneler kræver hverken autoriseret service eller tidskrævende vedligehold.
• Solceller er støjfri, forurener ikke og har ingen bevægelige dele, hvilket mindsker
service og vedligehold
• Solceller kan integreres i bygningers arkitektur eller anvendes som
bygningselement i form af tag, facader eller solafskærmning
• Solceller har lang levetid, med en produktionsgaranti på hele 25 år
• 10 kvadrameter solceller sparer ca. ½ ton CO2 om året

What I want :

• Solcellepaneler kræver hverken autoriseret service eller tidskrævende vedligehold.
• Solceller er støjfri, forurener ikke og har ingen bevægelige dele, hvilket mindsker
  service og vedligehold
• Solceller kan integreres i bygningers arkitektur eller anvendes som
  bygningselement i form af tag, facader eller solafskærmning
• Solceller har lang levetid, med en produktionsgaranti på hele 25 år
• 10 kvadrameter solceller sparer ca. ½ ton CO2 om året

Code atm:

List<string> items = new List<string>();

            items.Add("Solcellepaneler kræver hverken autoriseret service eller tidskrævende vedligehold.");
            items.Add("Solceller er støjfri, forurener ikke og har ingen bevægelige dele, hvilket mindsker service og vedligehold");
            items.Add("Solceller kan integreres i bygningers arkitektur eller anvendes som bygningselement i form af tag, facader eller solafskærmning");
            items.Add("Solceller har lang levetid, med en produktionsgaranti på hele 25 år ");
            items.Add("10 kvadrameter solceller sparer ca. ½ ton CO2 om året");



        Style style = document.AddStyle("MyBulletList", "Normal");
        style.ParagraphFormat.LeftIndent = "0.5cm";

        for (int idx = 0; idx < items.Count; ++idx)
        {
            ListInfo listinfo = new ListInfo();
            listinfo.ContinuePreviousList = idx > 0;
            listinfo.ListType = ListType.BulletList1;
            SolcellDummyText = HvadErSolceller.AddParagraph(items[idx]);
            SolcellDummyText.Style = "MyBulletList";
            SolcellDummyText.Format.ListInfo = listinfo;
            listinfo.ContinuePreviousList = true;

        }

Is there any way to catch newline event?

Timsen
  • 4,066
  • 10
  • 59
  • 117
  • I used last 5 hours to try get that to work.. so please no sarchasm.... – Timsen Mar 09 '12 at 11:34
  • what is items? you `TestTestTest` and `TestTestTest` store in one item? Show how items is filled...Need more info and explanation. Add more effort to create clear question. – Renatas M. Mar 09 '12 at 11:46
  • Updated, Items is just a List of Strings, filled up with HardCoded Text – Timsen Mar 09 '12 at 11:50
  • And now can you change `TestTestTest` lines to show how your original text looks like? New line in bullet starts because it doesn't fit in page? – Renatas M. Mar 09 '12 at 11:56
  • if text is hard coded adding some spaces doesn't work? – Renatas M. Mar 09 '12 at 12:47
  • Sample code added (to my answer below). Re "spaces": MigraDoc treats multiple spaces like a single space (similar to HTML). You have to use "non-breaking spaces" to use spaces for formatting - works best with Courier font (gives the good old-fashioned typewriter look). For modern applications, use tab stops and indentation, not spaces to format your text ... – I liked the old Stack Overflow Mar 12 '12 at 08:21

1 Answers1

18

Simply set the LeftIndent of the MyBulletList style to match the first tab stop, set the FirstLineIndent to a negative value to make space for the bullet - and that's all.

To keep it simple: the minimum requirements (assuming "paragraph" is the result of AddParagraph):

paragraph.Format.LeftIndent = "2.5cm";
paragraph.Format.FirstLineIndent = "-0.5cm";
paragraph.Format.ListInfo.ListType = ListType.BulletList1;

Here is sample code that uses a style (the style was previously created, the code snippet only modifies it):

style = styles["BulletList"];
style.ParagraphFormat.RightIndent = 12;
style.ParagraphFormat.TabStops.ClearAll();
style.ParagraphFormat.TabStops.AddTabStop(Unit.FromCentimeter(2.5), TabAlignment.Left);
style.ParagraphFormat.LeftIndent = "2.5cm";
style.ParagraphFormat.FirstLineIndent = "-0.5cm";
style.ParagraphFormat.SpaceBefore = 0;
style.ParagraphFormat.SpaceAfter = 0;

As mentioned before: the whole "trick" is setting LeftIndent and use a negative FirstLineIndent to position the bullet.

To add a style, get the Styles from the Document and call:

document.Styles.AddStyle("Bulletlist", "Normal");
Mouk
  • 1,807
  • 2
  • 18
  • 26