UpdateAllFields deprecated

11 posts, 0 answers
  1. John
    John avatar
    10 posts
    Member since:
    Aug 2010

    Posted 20 May 2014 Link to this post

    I have a custom set of fields in a document and am using UpdateAllFields() when I want to render a completed document. I notice from the documentation that this is deprecated. What should I be using instead?

    Thanks,
    John
  2. Petya
    Admin
    Petya avatar
    975 posts

    Posted 21 May 2014 Link to this post

    Hello John,

    Indeed, several methods of RadDocument including UpdateAllFields() were recently marked as obsolete. Instead of them, you should use the respective method of RadRichTextBox or in case the document is not shown in UI at this point - RadDocumentEditor. This article explains in details the purpose and possible uses of RadDocumentEditor.

    I hope this is helpful.

    Regards,
    Petya
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. John
    John avatar
    10 posts
    Member since:
    Aug 2010

    Posted 21 May 2014 in reply to Petya Link to this post

    Thanks. I am generating my document using code only so the RadDocumentEditor is the way to go. I am running in a thread so was hoping to avoid the "The calling thread must be STA, because many UI components require this" error. Since it looks like the RadDocumentEditor is designed for code only operation can you suppress this in future releases? (I've got round the problem using information from here at the moment.)
    Regards,
    John
  5. John
    John avatar
    10 posts
    Member since:
    Aug 2010

    Posted 22 May 2014 in reply to John Link to this post

    I've now added a xaml powered spinner which displays when the document is rendering. Unfortunately, the spinner stops turning when I run the thread that attaches to the UI, which makes my request for RadDocumentEditor to not require the UI thread even more important. Will you be able to implement this or is this outside of your control. Is there another way to run UpdateAllFields()?
    Thanks,
    John
  6. John
    John avatar
    10 posts
    Member since:
    Aug 2010

    Posted 22 May 2014 in reply to John Link to this post

    ok, I think I've narrowed this down to the PdfFormatProvider, not the RadDocumentEditor, so I've wrapped the pdf.Export() function in a   System.Windows.Application.Current.Dispatcher.Invoke call and that reduces the stoppage to a minimum.
    Regards,
    John
  7. Boby
    Admin
    Boby avatar
    595 posts

    Posted 26 May 2014 Link to this post

    Hi John,
    You are right, with the current implementation PDF export of RadRichTextBox's content can be performed only in the UI thread, as it uses UIElements which are then passed to the WPF printing system.

    Otherwise RadDocument can be created and manipulated using the RadDocumentEditor in a background thread.

    Don't hesitate to contact us if you have other questions.


    Regards,
    Boby
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  8. C
    C avatar
    43 posts
    Member since:
    Jul 2014

    Posted 02 Jul 2014 Link to this post

    John,

    Please post example code of how to do this using RadDocumentEditor.  I'm facing the same thing of creating a word document in code with no UI and a TOC field which needs to be updated before the document is written to a .docx file.
  9. John
    John avatar
    10 posts
    Member since:
    Aug 2010

    Posted 04 Jul 2014 in reply to C Link to this post

    C,

    Here is the code I use. I am using a xaml formatted document as the source, mail merging the fields and then converting it to pdf.

    The form for me is stored in a database, hence line 4 loading the layout from the FormDefinitionRepository.

    I also found that the pdf formatter can't handle errors in the merge/export particularly well so I found that updating it in xaml first then converting it to pdf did the trick for me. I know this isn't efficient but at least it doesn't kill the application.

    XamlFormatProvider provider = new XamlFormatProvider();
     
    // load the document
    RadDocumentEditor tb = new RadDocumentEditor(provider.Import(uow.FormDefinitionRepository.Single(w => w.Id == Request.FormId).Layout));
    tb.Document.MailMergeDataSource.ItemsSource = currEntity.EntityValues;

    // perform the merge
    tb.UpdateAllFields();
     
    // render it to xaml and back again
    // the Xaml exporter can handle errors in the merge whereas the pdf exporter can't
    // if the pdf exporter crashes it takes down the whole application so its safer to let the xaml exporter handle the errors
    string tempDoc = provider.Export(tb.Document);
    RadDocumentEditor mergedDoc = new RadDocumentEditor(provider.Import(tempDoc));
     
    // now set up the pdf export
    PdfFormatProvider pdf = new PdfFormatProvider();
     
    byte[] export = null;
     
    // The pdf export needs to be run on the UI thread otherwise it crashes with a "The calling thread must be STA,
    // because many UI components require this"
    System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new System.Action(() =>
    {
        try
        {
            export = pdf.Export(mergedDoc.Document);
            success = true;
        }
        catch (Exception e)
        {
            Log.Info("Pdf Conversion failed: FormId:{0} EntityId:{1} Exception:{2}", Request.FormId, Request.EntityId, e.Message);
            success = false;
        }
    }));

    Hope this helps.
    John
  10. Anand
    Anand avatar
    30 posts
    Member since:
    Jul 2014

    Posted 31 Jul 2014 in reply to Boby Link to this post

    Hi Boby,

    I have very similar issue to the one above. Have a big document of say 150 fields and I am trying to update all the fields in the document, and it takes at-least 2.5 mins to update it, since it is UI operation I have to do it on UI thread, which makes the UI to hang. 
    I tried SuspendUpdateLayout before calling UpdateAllFields, but no improvement. 

    Would appreciate, if you suggest me a solution to do this please. Below is the code snippet:

    var editor = new RadDocumentEditor(_richTextBox.Document)            {                               RespectDocumentProtection = false             };
    editor.UpdateAllFields(FieldDisplayMode.Result);
    and I tried calling straight on _richTextBox as well
    _richTextBox.UpdateAllFields(FieldDisplayMode.Result);

    Thanks 
    Anand



    _richTextBox.UpdateAllFields(FieldDisplayMode.Result);






  11. Boby
    Admin
    Boby avatar
    595 posts

    Posted 05 Aug 2014 Link to this post

    Hello Anand,
    Which is the version you are using? We have recently optimized the performance of the UpdateAllFields method and it currently updates document with 150 simple fields for about 2 seconds.

    I would also suggest you to open a separate support ticket and send us the problematic document (exported in XAML format) there - this would be the easiest way to investigate the problem.

    Regards,
    Boby
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  12. Anand
    Anand avatar
    30 posts
    Member since:
    Jul 2014

    Posted 13 Aug 2014 in reply to Boby Link to this post

    Hi Boby,

    Thanks for your reply. As you said, I read Telerik have improved the UpdateField performance. May be I will use the latest version and check how it works.

    Cheers
Back to Top
UI for WPF is Visual Studio 2017 Ready