PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Aug 03, 2021 10:37 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Apr 26, 2021 8:04 pm 
Offline

Joined: Mon Apr 26, 2021 7:58 pm
Posts: 3
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


Top
 Profile  
Reply with quote  
PostPosted: Tue Apr 27, 2021 6:13 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 655
Location: CCAA
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

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Sun May 02, 2021 7:07 pm 
Offline

Joined: Mon Apr 26, 2021 7:58 pm
Posts: 3
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


Top
 Profile  
Reply with quote  
PostPosted: Mon May 03, 2021 8:22 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 655
Location: CCAA
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

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 21 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