PdfDocumentSource for WPF / Features / Export PDF / Export PDF using Format Specific Filter
Export PDF using Format Specific Filter

PdfDocumentSource provides support for exporting a PDF file to an external format through Export method inherited from C1DocumentSource class.

To export PDF to HTML format

  1. Add a button control to the design view for exporting PDF.
  2. Switch to the code view and add the following namespaces in the code view.
    Imports C1.WPF.Document
    Imports C1.WPF.Document.Export
    
  3. Add a PDF file to the project. In our case, we have used PDF file named DefaultDocument.pdf.
  4. Initialize the instance of C1PDFDocumentSource class using the following code:
    Dim pds As New C1PdfDocumentSource()
    
  5. Load the PDf file into the object of C1PdfDocumentSource using the LoadFromFile method.
    pds.LoadFromFile("..\..\DefaultDocument.pdf")
    
  6. Add the following code to the button's click event to export the PDF to HTML format using HtmlFilter class.
    Try
            'Create HTMLFilter object
            Dim filter As New HtmlFilter()
            filter.ShowOptions = False
    
            'Open document after export
            filter.Preview = True
    
            'Set the output file name
            filter.FileName = "..\..\DefaultDocument.html"
    
            'Export PDF
            pds.Export(filter)
            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
    

To export PDF to an image file format

Similar code as above can be used for exporting a PDF document to a series of page image files in one of the supported image formats (JPEG, PNG, TIFF, etc.). It is also possible to create a single ZIP file containing the page images. The following code uses one of the image format filter class, JpegFilter, to export the multi-paged file to JPEG format and creates a single ZIP file of the exported images.

'Create JpegFilter object
Dim filter As New JpegFilter()
filter.UseZipForMultipleFiles = True
filter.ShowOptions = False

'Open document after export
filter.Preview = True

'Set the output file name
filter.FileName = "..\..\DefaultDocument.zip"

'Export PDF
pds.Export(filter)
MessageBox.Show(Me, "Document was successfully exported.", _
                "Information", MessageBoxButton.OK, _
                MessageBoxImage.Information)
See Also