# Export PDF using ExportProvider

## Content

PdfDocumentSource allows you to enumerate the supported export formats for a document using the [SupportedExportProviders](/componentone/api/wpf/online-document/dotnet-framework-api/C1.WPF.Document.4.6.2/C1.WPF.Document.C1PdfDocumentSource.SupportedExportProviders.html) property. The property returns a collection of ExportProvider classes that contain information about the supported formats, and can be used to create the corresponding export filter by using the [NewExporter](/componentone/docs/wpf/online-document/) method of [ExportProvider](/componentone/api/wpf/online-document/dotnet-framework-api/C1.WPF.Document.4.6.2/C1.WPF.Document.Export.ExportProvider.html) class.

Different document types support different sets of export formats, therefore enumerating and creating the export filters via **SupportedExportProviders** yields the correct results.

### To export PDF using supported exporters

1. Drag and drop Button and ComboBox controls from the **Toolbox** on the design view.
2. Switch to code view and add the following namespaces in the code view.
<br>
    ```vbnet
    Imports C1.WPF.Document
    Imports C1.WPF.Document.Export
    Imports Microsoft.Win32
    Imports C1.WPF
    ```

    ```csharp
    using C1.WPF.Document;
    using C1.WPF.Document.Export;
    using Microsoft.Win32;
    using C1.WPF;
    ```
3. Add a PDF file to the project. In our case, we have used PDF file named DefaultDocument.pdf from the product sample.
4. Initialize the instances of C1PDFDocumentSource and SaveFileDialog class using the following code:
<br>
    ```vbnet
    Dim pds As New C1PdfDocumentSource()
    Dim dialog As New SaveFileDialog()
    ```

    ```csharp
    C1PdfDocumentSource pds = new C1PdfDocumentSource();
    SaveFileDialog dialog = new SaveFileDialog();
    ```
5. Load the PDf file into the object of C1PdfDocumentSource using the [LoadFromFile](/componentone/docs/wpf/online-document/) method.
<br>
    ```vbnet
    pds.LoadFromFile("..\..\DefaultDocument.pdf")
    ```

    ```csharp
    pds.LoadFromFile(@"..\..\DefaultDocument.pdf");
    ```
6. Add the following code below **InitializeComponent()** method to get the list of supported exporters using **SupportedExportProviders** property.
<br>
    ```vbnet
    Dim supportedProviders = pds.SupportedExportProviders
    For Each sep As var In supportedProviders
         cbExporter.Items.Add(New C1ComboBoxItem() With { _
             Key .Content = [String].Format("Export to {0}...", sep.FormatName), _
             Key .Tag = sep _
         })
    Next
    ```

    ```csharp
    var supportedProviders = pds.SupportedExportProviders;
    foreach (var sep in supportedProviders)
        cbExporter.Items.Add(new C1ComboBoxItem()
        {
            Content = String.Format("Export to {0}...",
            sep.FormatName), Tag = sep
        });
    ```
7. Add the following code to create a method, **DoExport**, for exporting the PDF to another format using **Export** method.
<br>
    ```vbnet
    Private Sub DoExport(pds As C1PdfDocumentSource, ep As ExportProvider)
            dialog.DefaultExt = "." + ep.DefaultExtension
            dialog.FileName = System.IO.Path.GetFileName("Document")
            dialog.Filter = [String].Format("{0} (*.{1})|*.{1}|All files (*.*)|*.*", _
                                           ep.FormatName, ep.DefaultExtension)
            Dim dr As System.Nullable(Of Boolean) = dialog.ShowDialog(Me)
            If Not dr.HasValue OrElse Not dr.Value Then
                    Return
            End If
            Try
                    Dim exporter = ep.NewExporter()
                    exporter.ShowOptions = False
                    'Open document after export
                    exporter.Preview = True
                    'Set the output file name
                    exporter.FileName = dialog.FileName
                    'Export PDF
                    pds.Export(exporter)
                    MessageBox.Show(Me, "Document was successfully exported.", _
                                   "Information", MessageBoxButton.OK, _
                                   MessageBoxImage.Information)
            Catch ex As Exception
                    MessageBox.Show(Me, ex.Message, "Error", MessageBoxButton.OK, _
                                    MessageBoxImage.[Error])
            End Try
    End Sub
    ```

    ```csharp
    private void DoExport(C1PdfDocumentSource pds, ExportProvider ep)
    {
        dialog.DefaultExt = "." + ep.DefaultExtension;
        dialog.FileName = System.IO.Path.GetFileName("Document");
        dialog.Filter = String.Format("{0} (*.{1})|*.{1}|All files (*.*)|*.*",
                        ep.FormatName, ep.DefaultExtension);
        bool? dr = dialog.ShowDialog(this);
        if (!dr.HasValue || !dr.Value)
            return;
        try
        {
            var exporter = ep.NewExporter();
            exporter.ShowOptions = false;
            //Open document after export
            exporter.Preview = true;
            //Set the output file name
            exporter.FileName = dialog.FileName;
            //Export PDF
            pds.Export(exporter);
            MessageBox.Show(this, "Document was successfully exported.",
                            "Information", MessageBoxButton.OK, 
                            MessageBoxImage.Information);
        }
        catch (Exception ex)
        {
            MessageBox.Show(this, ex.Message, "Error", 
                            MessageBoxButton.OK, MessageBoxImage.Error);
        }
    }
    ```
8. Add the following code to the button's click event to call the DoExport method that accepts the object of C1PdfDocumentSource and ExportProvider as parameters.
<br>
    ```vbnet
    DoExport(pds, DirectCast(DirectCast(cbExporter.SelectedItem, C1ComboBoxItem).Tag, ExportProvider))
    ```

    ```csharp
    DoExport(pds, (ExportProvider)((C1ComboBoxItem)cbExporter.SelectedItem).Tag);
    ```

## See Also

[Export PDF using Format Specific Filter](/componentone/docs/wpf/online-document/PDFDocumentSource-for-WPF/Features/Export-PDF/Export-PDF-using-Format-Specific-Filter)
[Load PDF](/componentone/docs/wpf/online-document/PDFDocumentSource-for-WPF/Features/Load-PDF)
[Print PDF](/componentone/docs/wpf/online-document/PDFDocumentSource-for-WPF/Features/Print-PDF)
[Text Search](/componentone/docs/wpf/online-document/PDFDocumentSource-for-WPF/Features/Text-Search)