Как создать новый PDF-файл каждый раз, когда я повторяю или циклически просматриваю список документов
I am new to PDF creation and I am following the existing code to create a pdf file. I am amending the existing code by creating a new pdf. From the list of the documents, I am looping through each document and give it a new name. How do I create a new PDF file every time I iterate or loop through the documents list? resultCollection - Got the list of the documents currentCompanySegmentsSetings - An object with the details creatingTableOfContent - table content What I have tried
Что я уже пробовал:
foreach (var item in resultCollection) { var guidID = Guid.NewGuid().ToString(); var newFileName = $"{currentCompanySegmentsSetings.FriendlySegmentName}-{Translator.TranslateDocumentType("invoice", currentCompanySegmentsSetings).ToLower()}-{guidID}-{message.documents.First().AccountNumber}.pdf"; outputFileNames.Add(newFileName); //Create PDF's and send to the location System.IO.Directory.CreateDirectory(currentOutputDirectory); var firstDocsMetadata = resultCollection.First().MetaData; string generatedPDFLocation = System.IO.Path.Combine(currentOutputDirectory, newFileName); var file = DocumentsToPDFDocs(financialDocument); PdfDocument pdfDoc = new PdfDocument(new PdfWriter(generatedPDFLocation, CreateEncryptionWriteProperties())); Document doc = new Document(pdfDoc); //Bookmarks pdfDoc.GetCatalog().SetPageMode(PdfName.UseOutlines); doc.SetMargins(22f, 22f, 22f, 22f); doc.SetFontSize(8); doc.SetFontColor(Color.BLACK); //1.Create table of contents var tableOfContentTopMargin = 176; Table tableOfContent = creatingTableOfContent(file, currentCompanySegmentsSetings); tableOfContent.SetDestination("p" + "index"); doc.Add(tableOfContent.SetMarginTop(tableOfContentTopMargin)); //NOt sure how I can continue from here message.FinancialDocumentAttachments.Add(new MessageQueueAttachment() { Location = documentPath, IsNew = true, Id = Guid.NewGuid() }); }