This is a migrated thread and some comments may be shown as answers.

RadDocument - slows when adding more entries

4 Answers 105 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Jakub
Top achievements
Rank 1
Iron
Jakub asked on 02 Aug 2016, 10:12 AM

Hi,

i have a sample code:

                var document = new RadDocument();
            RadDocumentEditor editor = new RadDocumentEditor(document);
            editor.Document.LayoutMode = DocumentLayoutMode.Paged;
            editor.Document.CaretPosition.MoveToFirstPositionInDocument();
 
            for (int i = 0; i < 15000; i++)
            {
                stopwatch.Start();
                editor.InsertLine("TEST");
                stopwatch.Stop();
                System.Diagnostics.Debug.WriteLine(stopwatch.Elapsed);
                stopwatch.Reset();
            }

 

Why each of InsertLine call takes more time than previous?

 

When RadDocument contains more text it takes more time to insert? This document is not used or binded anywhere.

 

Thanks.

4 Answers, 1 is accepted

Sort by
0
Jakub
Top achievements
Rank 1
Iron
answered on 03 Aug 2016, 12:45 PM

Hi,

 

i checked in profiler and each of InsertLine calls later UpdateLayout(). Is there any possibility to SuspendNotifications or something similiar?

 

My goal is to collect data from database (many entries), insert it to raddocument and export to pdf. I takes so much time it is unacceptable.

 

After 3 minutes of inserting lines to radDocument, creating TableOfConentsField and then calling radDocumentEditor.InsertField(field, FieldDisplayMode.Result) takes 8 min.

 

Generated PDF has 900 pages. Is there any way to improve performance?

0
Tanya
Telerik team
answered on 05 Aug 2016, 08:40 AM
Hello Jakub,

The methods of RadDocumentEditor are used to guarantee that the RadDocument instance is properly updated and all required operations and updates are executed after modifying it. Thus, it triggers different methods that take care of these actions. We recommend using this class and its methods in scenarios where the edited document has been already measured.

However, when the document is just being created, you could directly use its model API to construct the desired content. With this approach, the performance would be better but you should have in mind that once the document is measured (for example, visualized, printed or some content is selected), the RadDocumentEditor should be used when you need to modify it.

Here is an example of how you could modify the sample snippet from your post to use the model:
RadDocument document = new RadDocument();
document.LayoutMode = DocumentLayoutMode.Paged;
Section section = new Section();
var stopwatch = new Stopwatch();
 
for (int i = 0; i < 1500; i++)
{
    stopwatch.Start();
 
    Span span = new Span("TEST");
    Paragraph paragraph = new Paragraph();
    paragraph.Inlines.Add(span);
    section.Blocks.Add(paragraph);
 
    stopwatch.Stop();
    System.Diagnostics.Debug.WriteLine(stopwatch.Elapsed);
    stopwatch.Reset();
}
 
document.Sections.Add(section);

Another approach that you could use to implement the end goal, is to create the document using our RadWordsProcessing library. This library is part of Telerik Document Processing and allows you create and modify documents of different file formats independently of platform and UI. You should be aware that, due to the specifics of the library, it currently doesn't support TOC fields. We have plans to implement this functionality in a future release and you could subscribe to get notifications about its progress through the related public feature request

Hope this helps.

Regards,
Tanya
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Jakub
Top achievements
Rank 1
Iron
answered on 05 Aug 2016, 12:58 PM

Hey,

 

thank you, it really helped. Now I'm creating my whole RadDocument in ~20sec.

 

Still, I coudn't find any better solution to create ToC. Inserting field TableOfContentsField and calling pdfFormatProvider.Export to export pdf to file takes 6-7 min.

 

It is UpdateAllFields called 'under the hood' takes this time or something else?

 

As I mentioned in my previous post: I'm creating ~900 pages document and ToC contains 15-20 pages of links.

0
Tanya
Telerik team
answered on 10 Aug 2016, 08:15 AM
Hello Jakub,

When inserting and updating a TOC field, the whole document should be measured and arranged in order to update the field with the proper values. This involves the execution of many update operations which cannot be reduced.

In regards to the export to PDF, the situation is pretty similar - the engine ensures that everything (including TOC fields) is updated and measured so the content is properly drawn in the PDF document.

With that said, I'm afraid there isn't much we could do in order to speed up the process when dealing with such big documents.

Regards,
Tanya
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
RichTextBox
Asked by
Jakub
Top achievements
Rank 1
Iron
Answers by
Jakub
Top achievements
Rank 1
Iron
Tanya
Telerik team
Share this question
or