Document templates

11 posts, 0 answers
  1. Daní
    Daní avatar
    303 posts
    Member since:
    Feb 2008

    Posted 28 Mar 2012 Link to this post

    Hello,

    I have a requirement to build a document generation engine and I'd like to know if it might be implemented with the RichTextBox. The idea is provide users, in the healtcare area, with document templates for fast full fill. A document template will contain;
    • read only fixed regions, 
    • read only dynamic regions (for example, patient info that will be filled dynamically depending on the patient) 
    • and dynamic regions to be filled by the user (typically a doctor). These region might contain free text provided by the user o "assisted text", for example a list of medicine to be supplied, a list of diagnoses... it woul be nice a feature similar to autocomplete, or suggestion list.
    • a navigation tree to quickly access to the desired region
    • my customer wishes a tool to generate these templates by medician experts

    Do you think these requirements may be implemented with RadRichTextBox, if so, any guide to start working?

    Thanks
  2. Boby
    Admin
    Boby avatar
    595 posts

    Posted 30 Mar 2012 Link to this post

    Hello Daní,
    Read-only regions can be implemented with document protection, as described in this help article and shown in this demo. For quick navigation around the document you can use bookmarks.
    RadRichTextBox doesn't provide auto-complete and it is generally considered out of its scope, but you may come up with some custom solution, showing suggestions depending on the region containing current caret position.

    Regards,
    Boby
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. Daní
    Daní avatar
    303 posts
    Member since:
    Feb 2008

    Posted 30 Mar 2012 Link to this post

    Hi Bobby,

    Thanks for your response. But, still, I'm not sure if I can face these requirement using RichTextBox.
    • For AutoComplete or suggestion list feature, do you thin I can use Inline UI controls?
    • One of the key points is the tool to generate dynamically new templates and editing existing ones. I imagine it as a Desig surface, where user can places "controls" (readonly text areas, medicines list control, diagnoses list controls, a "patient info" control that would load data dynamically depending on the current patien,...). Once the user submits his design, I should generate by code dynamically a RichTextBox document that would serve as document template.

    I'd like to know what do you think (or purpose) about this approach and if you think about its viability in a reasonable time period (2-3 months).

    Thanks

  5. Boby
    Admin
    Boby avatar
    595 posts

    Posted 04 Apr 2012 Link to this post

    Hi Daní,

    To your questions:
    • The purpose of InlineUIContainers is to hold custom UI elements which act as document Inlines (you can find an image of document elements hierarchy here). Inlines display content that flows correctly in its parent paragraph. Maybe it should be better to use a popup or to customize the built-in context menu to show the suggestions. To mark the different regions (diagnoses, medicines), you can use custom annotations.
    • RadRichTextBox can be used as a tool to generate such reports, as it is capable of creating bookmarks and document protections regions even with its built-in default UI. With regard to the custom annotations part, you can easily add some new tabs and buttons for dealing with them. Exporting to XAML will create the template which can be subsequently loaded by an instance of RadRichTextBox with different active user set to the property RadRichTextBox.CurrentUser.
      You can also review our Mail Merge demo (and the help article here), which demonstrates document generation depending on the data source.
    I hope this helps.

    Kind regards,
    Boby
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. Daní
    Daní avatar
    303 posts
    Member since:
    Feb 2008

    Posted 04 Apr 2012 Link to this post

    Hi Booby,

    I've seen MailMerge demo and I think merge fields can be very helpful. For instance, I think it'll be easier for me, and even for users, to create a view where users may edit the dynamic fields. Besides, I think I can generate a RadDocument template with the fixed paragraphs and use merge fields for the dynamic content. Once user submits the edition view, I can perform the document merge with the fullfilled data by the user and generate the final document. I think this approach maybe the easiest and the mos powerfull, as administrative users may edit the "template", modifying the fixed parts and customizing the final document appearance.

    What is shown in the MailMerge demo is a very basic scenario. I don't know if I can use collection and nested properties as merge fields, can I?

    Thanks
  7. Daní
    Daní avatar
    303 posts
    Member since:
    Feb 2008

    Posted 05 Apr 2012 Link to this post

    Hi after some research and testing of some of the RadRcihTexBox features, I think that merge fields can fit really fine to my requirements. In summary, by approach will be formed by 3 steps:

    1. Template generation: an specialized user, will generate the document template, adding fixed text areas, headers, footers... And also providing dynamic merge fields. To do this task, I'll provide a user interface very similar to the TelerikEditor demo. The template wiil be saved at server as .xaml file.
    2. Data fullfill: users, normally doctors, wiil have to fullfill a custom form, a Silverlight User control, with visual elements bounds to the properties of view model object instance.
    3. Once the data form fullfill is completed and users submits it, the application will download the .xaml template form server and will merge fields against the view model instance to generate the final document.

    I have performed some testing with merge fields. They work fine when underlying properties are string typed. Unfortunately, my view model class is a bit more complex. It contains, basically, string properties (no matter with these), object collections (I'd like they being merged as tables), and rich text properties (user fullfills some data in the fullfilment form wiht RadRichTextBoxs, using XamlDataProvider for binding, causes that when merging these properties the documents contains the xaml text, not the formatted result).

    So, I'd like to know if there is any extension/customization method for merge fields that allows to supply the formatted result for a property type.

    Thanks.

  8. Daní
    Daní avatar
    303 posts
    Member since:
    Feb 2008

    Posted 05 Apr 2012 Link to this post

    I think I can solve all my obstacles. I have just created several custom merge fields classes, inheriting from MergeField class. Just overriding some MergeField members (FieldTypeName, CreateInstance and GetResultFragment) and then registering these field types with CodeBasedFieldFactory.RegisterFieldType allows me to customize the merging feature. I have created a custom "Insert Merge Field" RibbonDropDownButton for the RichtTextBox RibbonView that allows me to create/modify templates using the custom fields and everything works like a charm.

    Wow, RadRichTextBox offers really a lot of useful features. However, it's a bit difficult to delve with all richtextbox feature because is a really huge control and, sometimes, is difficult to find precise information.
  9. Boby
    Admin
    Boby avatar
    595 posts

    Posted 09 Apr 2012 Link to this post

    Hello Daní,
    I was about to point you to the answer in this forum thread, containing a demo project demonstrating the usage of custom merge fields, but it looks you manage to implement such already. The built-in merge fields internally uses Binding objects, so you can use the familiar property path syntax.
    We are constantly working on improving the documentation, so if you have any specific suggestions for its improvement or have found any omissions, we'd be glad if you share them with us.

    All the best,
    Boby
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  10. Daní
    Daní avatar
    303 posts
    Member since:
    Feb 2008

    Posted 09 Apr 2012 Link to this post

    Hello Bobby

    I don't have any complaint about documentation. I assume that, fortunately, telerik's toolset  is constantly growing up and that new features are being added to existing controls, besides, some controls like GridView and RichTextBox are rully huge, so it's difficult to keep documentation up to date. Of course, everything can be improved and telerik's documentation is not an exception, but the the lack of documentation in some features is compensated with a great support in this forum, support tickets... so, in average, I'm quite satisfied with telerik's support.
  11. Daní
    Daní avatar
    303 posts
    Member since:
    Feb 2008

    Posted 09 Apr 2012 Link to this post

    Hello,

    Once I've solved merge fields customization, I need to supply a RadDocumentFragment in GetResultFragment method for each custmo merge field. Of course, I can generate the RadDocumentFragment by adding RichTextBox elements (paragraphs, sections, borders, tables,...) by code. But it would be easier for me to design DataTemplates or User Controls to be added to RadRichTextBox inside an InlineUIContainer. In my first attemp, to avoid to generate a Table programatically, I've tried to add a RadGridView inside an InlineUIContainer. So what I've tried is:
    • I've created a DataTemplate with a RadGridView where I've defined the desired columns.
    • In the inherited MergeField class, in GetResultFragment override method, I obtain, via propertypath, a collection of items.
    • Then, I instantiate a RadRichTextBox on the fly. I also instantiate a ContentPresenter control setting the items collection as the Content property and the DataTemplate as the ContentTemplate.
    • I've added a InlineUIContainer to the RadRichTextBox containing the ContentControl.
    • Finally, I've called RadRichTextBox.Document.Selection.SelecAll() method and I'm returning the DocumentFragment by calling CopySelectedDocumentsElements method.

    Unfortunately, when printing or saving the final document, nothing appears. 

    To summarize what I'm doing, i hace to say that finall RadRichTextBox is created on the fly, When user submits the edition form, I create a RichTextBox in the fly preloaded with the ".xaml document template", then I supply the mail merge items source and call the MailMerge method. MailMerge Methods causes that all dynmic fields being calculated, so GetResultFragment method is called. Finally, I'm calling the Print method on RichTextBox.

    so, can i supply DataTemplates (or UserControls) when merging fields to easyly design the finall content?

    Thanks
  12. Boby
    Admin
    Boby avatar
    595 posts

    Posted 12 Apr 2012 Link to this post

    Hello Daní,

    I am not sure I understand your implementation well. Are you using an instance of RadRichTextBox just to create a document fragment?
    You should also note that serialization (saving) of the content of the InlineUIContainers is not always possible, especially for complex controls such as RadGridView. In addition, customization of the export process cannot be achieved with the current version (we are planning to expose InlineUIContainerExporting event similar to the one found in HtmlExportSettings, but this is not scheduled yet).
    Here is a sample implementation of GetResultFragment for custom merge field returning document fragment containing RadGridView:
    protected override DocumentFragment GetResultFragment()
    {
        Customer customer = this.Document.MailMergeDataSource.CurrentItem as Customer;
        if (customer == null)
        {
            return null;
        }
     
        if (this.PropertyPath == "Orders")
        {
            RadDocument document = CreateDocumentWithRadGridView(customer);
            return new DocumentFragment(document);
        }
     
        return null;
    }
     
    private RadDocument CreateDocumentWithRadGridView(Customer customer)
    {
        RadGridView gridView = new RadGridView()
        {
            ItemsSource = customer.Orders
        };
     
        Paragraph paragraph = new Paragraph();
        paragraph.Inlines.Add(new InlineUIContainer(gridView, new System.Windows.Size(gridView.ActualWidth, gridView.ActualHeight)));
     
        Section section = new Section();
        section.Blocks.Add(paragraph);
     
        RadDocument document = new RadDocument();
        document.Sections.Add(section);
     
        document.MeasureAndArrangeInDefaultSize();
        return document;
    }
    which is modified part of the sample project found here; but it won't work in your case either, as XamlReader cannot successfully load the RadGridView serialized on document export.

    As a general rule, we suggest using InlineUIContainer only in much simpler cases, and in your scenario it's probably better to use the document model.

    Regards,
    Boby
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
DevCraft banner