PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Creating multiple PDF-documents? https://forum.pdfsharp.net/viewtopic.php?f=2&t=4286 |
Page 1 of 1 |
Author: | Flidrip [ Tue Sep 28, 2021 8:41 am ] |
Post subject: | Creating multiple PDF-documents? |
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: Code: var listName = collectionName .GroupBy(p => new { p.propertyName }) .ToList(); Trying to execute my PDFsharp-code for every propertyName in listName: Code: 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): Code: // Continued System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); 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 doc.Save("C:\My\File\Path\Test.pdf"); 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? |
Author: | TH-Soft [ Tue Sep 28, 2021 8:18 pm ] |
Post subject: | Re: Creating multiple PDF-documents? |
Answered on SO: https://stackoverflow.com/a/69360036/162529 |
Author: | Flidrip [ Thu Sep 30, 2021 12:06 pm ] |
Post subject: | Re: Creating multiple PDF-documents? |
Thanks alot! |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |