PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

New Line by Items of an Array
https://forum.pdfsharp.net/viewtopic.php?f=2&t=4249
Page 1 of 1

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

Hi,
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?

Code:
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!
Greetings
Sascha

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

Hi!
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.
http://pdfsharp.net/wiki/Invoice-sample.ashx

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:
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.AddFormattedText("Fach:",TextFormat.Bold);
            para.AddText(FachItem);
            para.Format.Font.Name = "Garamond";
            para.Format.Font.Size = 12;
            para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.Black;


Thank you very much and greetings
Sascha

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:
http://pdfsharp.net/wiki/HelloMigraDoc-sample.ashx

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/