[]
        
(Showing Draft Content)

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
    using C1.WPF.Document;
    using 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()
    C1PdfDocumentSource pds = new C1PdfDocumentSource();
  5. Load the PDf file into the object of C1PdfDocumentSource using the LoadFromFile method.


    pds.LoadFromFile("..\..\DefaultDocument.pdf")
    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
    try
    {
        //Create HTMLFilter object
        HtmlFilter filter = 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(this, "Document was successfully exported.",
                        "Information", MessageBoxButton.OK,
                        MessageBoxImage.Information);
    }
    catch (Exception ex)
    {
        MessageBox.Show(this, ex.Message, "Error",
                        MessageBoxButton.OK, MessageBoxImage.Error);
    }

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)
//Create JpegFilter object
   JpegFilter filter = 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(this, "Document was successfully exported.",
                "Information", MessageBoxButton.OK,
                MessageBoxImage.Information);
}

See Also

Export PDF using ExportProvider

Print PDF

Text Search