PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Dec 03, 2021 12:49 pm

All times are UTC

Forum rules

Please read this before posting on this forum: Forum Rules

Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Sep 28, 2021 8:41 am 

Joined: Tue Sep 28, 2021 8:33 am
Posts: 4
Using PDFSharp, I would like to create one PDF-document for each distinct value in the property of the List I am looping through.

Grouping my collection, and creating a List:

var listName = collectionName
    .GroupBy(p => new { p.propertyName })

Trying to execute my PDFsharp-code for every propertyName in listName:

foreach (var trip in paidTrip) {
    // Getting just the name string from the specific propertyName key
    string[] remove = { "{", "}", "propertyName", "=" };
    string pnString = trip.Key.ToString();
    foreach (string item in remove) {
        pnString = pnString.Replace(item, string.Empty);

Right here is where I believe I drop the ball; how can I bring each name with me to their distinct PDF-document? I am missing that connection. So, underneath this, I start creating my PDF-document(s):

    // Continued
    PdfDocument doc = new();
    PdfPage page = doc.AddPage();
    XGraphics gfx = XGraphics.FromPdfPage(page);
    // Adding fonts and brushes...
    // Adding some text, to check If I am able to grab the names of propertyName (which I am - but jut the first, once)...
    gfx.DrawString(pnString, new XFont("Arial", 40, XFontStyle.Bold), myGreen, new XPoint(5, 250));

    // And then, saving the PDF-document

But as I said, this just saves one PDF for the first name found. I believe it is trying to save one file per name found, but it can't, because the file has already been created with the file name specified.

So my question is: how can I make sure that each name found in the foreach loop is brought with me to when I create the PDFs, and save one PDF-document for each of them?

Reply with quote  
PostPosted: Tue Sep 28, 2021 8:18 pm 
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 683
Location: CCAA
Answered on SO:

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

Reply with quote  
PostPosted: Thu Sep 30, 2021 12:06 pm 

Joined: Tue Sep 28, 2021 8:33 am
Posts: 4
Thanks alot!

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

All times are UTC

Who is online

Users browsing this forum: No registered users and 61 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