PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Apr 28, 2024 5:09 am

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
 Post subject: PDF speed question
PostPosted: Fri Nov 22, 2013 10:48 pm 
Offline

Joined: Fri Nov 22, 2013 10:41 pm
Posts: 2
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: PDF speed question
PostPosted: Mon Nov 25, 2013 9:15 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi!

Did you try a Release build? Should be faster.

IMHO you don't need AddFormattedText.
What I would do: Just add a Paragraph and assign either "FolderStyle" or "ItemStyle" to it (these styles have to be added, of course).
Indentation could be done with TabStops instead of spaces.
I have no idea if any of these suggestions will make the program run faster.

BTW: You can also create an RTF file to see how long that takes. And then load it with Word and wait until Word has determined the page count and see how long that takes.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: PDF speed question
PostPosted: Mon Nov 25, 2013 4:30 pm 
Offline

Joined: Fri Nov 22, 2013 10:41 pm
Posts: 2
Hey Thomas,

Thanks for the quick reply.

I'll try your suggestions.

In regards to the release build - I installed it via Nuget which gave me this one:

http://www.nuget.org/packages/PDFsharp-MigraDoc-GDI/

Is this a release build?

If not, where can I download it from?

Thanks !


Top
 Profile  
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: Google [Bot] and 345 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