Hey guys,
I'm relatively new to C# but am using your awesome library to create PDFs. Basically, I have a database backend that supplies 500,000 records and I need to save them into a PDF. It's a directory structure, so I've used a recursive loop to do it.
Here's the code for it:
Code:
public void printProject(Document document, string parentNode, Section section)
{
using (Entities ctx = new Entities())
{
foreach (bFile b in fileList)
{
count++;
if (b.Type == "folder")
{
Paragraph folderText = section.AddParagraph();
folderText.AddSpace(3 * indentCount);
folderText.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.BlueViolet;
folderText.Format.Font.Size = 6;
folderText.AddFormattedText(b.FileName + " (" + b.Date + ")", TextFormat.Bold).AddLineBreak();
printProject(document, b.BoxID, section);
}
else
{
Paragraph childText = section.AddParagraph();
childText.AddSpace(3 * (indentCount+1));
childText.AddFormattedText(b.FileName + " (" + b.Date + ")").AddLineBreak();
childText.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.CadetBlue;
childText.Format.Font.Size = 5;
}
}
}
}
}
The code may be incomplete to protect privacy, but I basically run that loop for 300,000 items.
The report is taking 20 minutes to write. Is there any way I can optimize this? Am I making the pdf correctly? I tried running without pdfSharp and it finishes much quicker so it's not a DB issue.
Any idea?
Many thanks.