New to Telerik UI for WinForms? Download free 30-day trial

Import/Export Settings

As sometimes the formats may support several ways for presenting one and the same content, some customization options have been provided in order to specify the result which the user expects. This is achieved with the help of import and export settings, which some format providers expose (HtmlFormatProvider and PdfFormatProvider). You need to create an instance of the settings and assign it to the property of the provider you will be using. Then, you can set (or retrieve) the properties you need. HtmlFormatProvider makes use of HtmlExportSettings and HtmlImportSettings to control import/export.

1. HtmlExportSettings provides the following options:

  • DocumentExportLevel – you can choose between Document and Fragment. Document is the default value, which includes the HTML declaration, the , , and tags, whereas setting the document export level to Fragment results in exporting the content of the tag only.

  • StylesExportMode – the options here are Inline and Classes, the default one being Classes. Predefined classes is the preferred way for setting styles, yet inline styles may be useful with regard to the consumer of the HTML. For instance, in order to use the exported HTML in Telerik Reporting, the StylesExportMode needs to be set to Inline.

  • ImageExportMode – the user can choose between several options or even provide his own implementation by choosing the ImageExportingEvent option for the ImageExportMode property and handling the ImageExportingEvent. The UriSource option can be used if you want to export an image by setting its src property to the URL rather than having the raw data in the exported document.

2. HtmlImportSettings provides the following options:

  • UseDefaultStylesheetForFontProperties – a Boolean property indicating whether the default font properties of RadRichTextBox or the defaults in the HTML specification should be used for the elements that do not set their FontSize, FontFamily, FontWeight and FontStyle explicitly.

  • LoadImageFromUrl event – this event was introduced at a time when HtmlFormatProvider did not automatically load images from URLs. The feature is currently supported out of the box, but this event can be useful if using virtual directories and files on the server.

PdfFormatProvider exposes an ExportSettings property of type PdfExportSettings, which can be used in the same way as the export settings of HtmlFormatProvider.

PdfExportSettings include the following options:

  • ContentsCompressionMode – this property allows you to choose if you wish to make use of compression (by setting it to Deflate or Automatic) or not (PdfContentsCompressionMode.None) of the text content of the document.

  • ContentsDeflaterCompressionLevel – an integer between -1 and 9, used to get or set the compression level to be used when deflating the content of the document. Default Compression is -1, No Compression is 0 and Best Compression is 9;

  • ImagesCompressionMode – the user can choose between None, Jpeg (supported only for images, imported as JPEG), Deflate (the deflate algorithm will be applied to compress the images) or Automatic (the best algorithm will be automatically decided upon for you).

  • ImagesDeflaterCompressionLevel – same as ContentsDeflaterCompressionLevel, but applied to the images in the document. This property is respected when an image is compressed with Deflate.

PDF import is currently not supported, so there are not any import settings.

There are not any Import or ExportSettings for XAML either, as the XAML serialization is lossless and all elements are imported and exported as they would appear if declared in a XAML page in the application. DocxFormatProvider does not currently provide any settings as the document content is matched as closely as possible to the Word document.

In this article