PDFsharp & MigraDoc Foundation

New Line by Items of an Array
Page 1 of 1

Author:  Sascha [ Mon Apr 26, 2021 8:04 pm ]
Post subject:  New Line by Items of an Array

at first sorry for my bad english. Iam from Germany and im new at the programming with c# and to use PDFsharp.

At the moment i get some Items/Values from a ListBox. The user has the chance to select more then one item.

This is my code to print the String. My Problem is: When i selected more then one Item from the Listbox he write all Items in one line.
How can i get an line break?

foreach (object selectedItem in listKompetenz.SelectedItems)
                DataRowView dr = (DataRowView)selectedItem;
                String result = dr["kompetenz"].ToString() + "\n";
                string kompetenzItem = result + "\n";
                tf.Alignment = XParagraphAlignment.Left;
                tf.DrawString(kompetenzItem + "\n", font, XBrushes.Black, new XRect(40, 320, 500, 300), XStringFormats.TopLeft);

Thank you very much for your help!

Author:  TH-Soft [ Tue Apr 27, 2021 6:13 am ]
Post subject:  Re: New Line by Items of an Array

You draw all the items, one after the other, at the same location "40, 320, 500, 300". Increase the Y value after each line, depending on the font size. Add pages when needed.
With PDFsharp you have full control over everything.

Or make a single long string with line breaks and invoke DrawString only once for all items. You still need extra code for page breaks.

To get automatic line breaks, automatic page breaks, and tables, try MigraDoc.

Author:  Sascha [ Sun May 02, 2021 7:07 pm ]
Post subject:  Re: New Line by Items of an Array

It works fine. Thank you very much.

I got another question. I want do have some diffent text size. How can i do it?

My Code:
// You always need a MigraDoc document for rendering.
            Document doc = new Document();
            Section sec = doc.AddSection();
            // Add a single paragraph with some text and format information.
            Paragraph para = sec.AddParagraph();
            para.AddText("Individueller Förderplan von \n" + name.Text);
            para.Format.Font.Name = "Garamond";
            para.Format.Font.Size = 20;
            para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.Black;
            para.Format.Font.Bold = true;

            var FachItem = (listFach.SelectedItem as DataRowView)["fach"].ToString();

            Paragraph para = sec.AddParagraph();
            para.Format.Font.Name = "Garamond";
            para.Format.Font.Size = 12;
            para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.Black;

Thank you very much and greetings

Author:  TH-Soft [ Mon May 03, 2021 8:22 am ]
Post subject:  Re: New Line by Items of an Array

Sascha wrote:
I want do have some different text size. How can i do it?
Your code looks OK and I assume it is working.
The better and nicer approach is using styles.
See DefineStyles here:

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group