HTML5 Viewer: Restricting Export Formats

Valid from List & Label 23
It is often necessary to limit the available export formats in the HTML5 Viewer, so that e. g. the selection becomes clearer for the user:


So that now e. g. only the three formats "Adobe PDF Format","Microsoft Excel Format" and "Microsoft Word Format" are displayed, one of the following mechanisms can be implemented in the .NET Web application:

1. Extend existing event OnListLabelRequest()
The event OnListListLabelRequest() is used to establish a connection between the Html5ViewerControl and the used List & Label object. The List & Label object to be used is created here and at least the data source to be used is assigned for print/export. At this point, you can now additionally make sure that the export formats to be displayed in the Html5ViewerControl are restricted accordingly, which is done with the option LlOptionString.Exports_Allowed:
[code] namespace WebReporting { public partial class HTML5Viewer : System.Web.UI.Page { protected void Page_Load(object sender, System.EventArgs e) { // do some stuff...
		// define the Html5ViewerControl options
		Html5ViewerOptions options = new Html5ViewerOptions();
		options.OnListLabelRequest += Services_OnListLabelRequest;
		options.UseUIMiniStyle = true;
		
		// apply options to the Html5ViewerControl
		this.Html5ViewerControl1.Options = options;
		
		// do some other stuff...
	}
	
	void Services_OnListLabelRequest(object sender, ListLabelRequestEventArgs e)
    {
		try
        {
			// create the List & Label object for the HTML5ViewerControl
			ListLabel LL = new ListLabel();

			// set license key for List & Label (client + server)
            // if not set, a license error will be displayed on non-development machines
			LL.LicensingInfo = "<ToDo: insert license here>";
        
			// do some List & Label stuff here - e.g. setting the DatSource property etc.
			// ...
			
            // set the following option to restrict the available export formats in the HTML5ViewerControl to PDF, Excel and Word
            LL.Core.LlSetOptionString(LlOptionString.Exports_Allowed, "PDF;XLS;DOCX");

			// return the configured List & Label object
            e.NewInstance = LL;
        }
        catch (ListLabelException LlException)
        {
            Response.Write("<br><br><b>An error occurred:</b> " + LlException.Message);
            LL.Dispose();
            return;
        }
	}
}

}
[/code]

2. Use the event OnRenderExportLinks()
This event is called as soon as the Export button is clicked in HTML5ViewerControl and already contains the list of the standard export formats of List & Label, which can now be adjusted. For this purpose, unwanted export formats can be easily removed from the e.ExportLinks list:

namespace WebReporting
{
    public partial class HTML5Viewer : System.Web.UI.Page
    {
        protected void Page_Load(object sender, System.EventArgs e)
        {
			// do some stuff...
			
			// define the Html5ViewerControl options
			Html5ViewerOptions options = new Html5ViewerOptions();
			options.OnListLabelRequest += Services_OnListLabelRequest;
			options.OnRenderExportLinks += Services_OnRenderExportLinks;
			options.UseUIMiniStyle = true;
			
			// apply options to the Html5ViewerControl
			this.Html5ViewerControl1.Options = options;
			
			// do some other stuff...
		}
		
		private void Services_OnRenderExportLinks(object sender, RequestExportLinksEventArgs e)
        {
            IList<ViewerExportLink> listAllExportFormats = e.ExportLinks.ToList<ViewerExportLink>();
            IList<ViewerExportLink> listRestrictedExportFormats = e.ExportLinks;
            foreach (ViewerExportLink exportLink in listAllExportFormats)
            {
                // only allow PDF, Excel and Word
                if (
                    exportLink.Format != "PDF"
                    && exportLink.Format != "XLS"
                    && exportLink.Format != "DOCX"
					)
                {
                    // remove unwanted export format from list
                    listRestrictedExportFormats.Remove(exportLink);
                }
            }
        }
	}
}


Note: The ExportLinks property of the Html5ViewerControl’s options even allows you to create your own complete list of export formats. However, the OnRenderExportLinks() event is no longer called!

Both variants have the result that in HTML5 Viewer only the three restricted formats “Adobe PDF Format”, “Microsoft Excel Format” and “Microsoft Word Format” are available:

IDKBTE001340 KBTE001340