ComponentOne Document Library for WinForms
Export PDF using Format Specific Filter
PdfDocumentSource for WinForms > Features > Export PDF > 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 form for exporting PDF.
  2. Drag and drop C1PdfDocumentSource component from the Toolbox on the form to add it to the component tray.
  3. Switch to the code view and add the following namespace in the code view.
    Imports C1.Win.C1Document.Export
    
    using C1.Win.C1Document.Export;
    
  4. Add a PDF file to the project. In our case, we have used PDF file named DefaultDocument.pdf.
  5. Load the PDf file into the object of PdfDocumentSource using the LoadFromFile method.
    C1PdfDocumentSource1.LoadFromFile("..\..\DefaultDocument.pdf")
    
    c1PdfDocumentSource1.LoadFromFile(@"..\..\DefaultDocument.pdf");
    
  6. Add the following code to the button's click event to export the PDF to HTML format using HtmlFilter class.
    'Create HTMLFilter object
    Dim filter As New HtmlFilter()
    'Set the output file name
    filter.FileName = "..\..\DefaultDocument.html"
    filter.ShowOptions = False
    
    If filter.ShowOptionsDialog() Then
        'Export PDF
        C1PdfDocumentSource1.Export(filter)
        System.Diagnostics.Process.Start(filter.OutputFiles(0))
        MessageBox.Show(Me, "Document was successfully exported.",
                        "Information", MessageBoxButtons.OK,
                        MessageBoxIcon.Information)
    End If
    
    //Create HTMLFilter object
    HtmlFilter filter = new HtmlFilter();
    //Set the output file name
    filter.FileName = @"..\..\DefaultDocument.html";
    filter.ShowOptions = false;
                
    if (filter.ShowOptionsDialog())
    {
        //Export PDF
        c1PdfDocumentSource1.Export(filter);
        System.Diagnostics.Process.Start(filter.OutputFiles[0]);
        MessageBox.Show(this, "Document was successfully exported.",
                        "Information", MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
    }
    

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.FileName = "..\..\DefaultDocument.zip"
filter.UseZipForMultipleFiles = True
filter.ShowOptions = False

If filter.ShowOptionsDialog() Then
    'Export PDF
    C1PdfDocumentSource1.Export(filter)
    System.Diagnostics.Process.Start(filter.OutputFiles(0))
    MessageBox.Show(Me, "Document was successfully exported.",
                    "Information", MessageBoxButtons.OK,
                    MessageBoxIcon.Information)
End If
//Create JPEGFilter object
JpegFilter filter = new JpegFilter();
filter.FileName = @"..\..\DefaultDocument.zip";
filter.UseZipForMultipleFiles = true;
filter.ShowOptions = false;

if (filter.ShowOptionsDialog())
{
    //Export PDF
    c1PdfDocumentSource1.Export(filter);
    System.Diagnostics.Process.Start(filter.OutputFiles[0]);
    MessageBox.Show(this, "Document was successfully exported.",
                    "Information", MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
}
See Also