The Convert File application is a simple application that converts a single, chosen file using Document Conversion Service and a selected conversion profile. It also includes the ability to convert the file remotely on another computer.  

This application is also provided as a Visual Studio project in both VB.NET and C#.NET and shows how to convert a file using the provided .NET library, PEERNET.ConvertUtility.dll.

 

The type of output created is based on the conversion profile chosen. A selection of common conversion profiles are included with the Document Conversion Service install. See Creating and Customizing Profiles for more information about the contents of the profiles, a list of profiles included with Document Conversion Service, and how to create your own.

The application uses the file extension of the source file to determine what converter to use to convert the file. The default file extension to converter mapping provided through the PEERNET.ConvertUtility.dll is used. As with profiles, this file extension mapping can be customized, but rarely needs to be. See the section File Extension to Converter Mapping for details.

You can also use this program to test remote document conversion by following the steps in Setting up Client-Server Conversion.

Running the Convert File Application

Before you begin...

Before running the application, follow the steps in Starting and Stopping the Service to start the Document Conversion Service. If the service is not started, an error message will display when you try to convert documents.

 

1.Open the application by going to Start - All Programs - PEERNET Document Conversion Service 3.0 – Convert a File....

2.Choose a file to convert using the Browse button or typing in the file name. The Output File Name field will be populated from the chosen file name.

3.Choose a folder in which to save the output file.

4.Use the Convert to Type drop down list to select your output format from the list of available profiles.

5.Click Convert to convert the chosen file. When the conversion process is finished, the results are displayed in the listbox at the bottom.

Inside the Sample Code - Calling the PEERNET.ConvertUtility.dll Methods

The conversion process itself happens in the Click event handler of the "Convert File" button. Below is a simplified version of the C# version of that event. Field checking and error reporting is stripped out for brevity.

Go to Start - All Programs - PEERNET Document Conversion Service 3.0 – Samples - Open Samples Folder to see the C# or VB.NET sample code for the full function in the language of your choice.

Code Sample - Click Event Handler for Convert File in C#

 
using PEERNET.ConvertUtility;
 
private void btnConvert_Click(object sender, EventArgs e)
{
    // conversion results returned, use to find files created or errors
    PNConversionItem resultItem = null;
 
    try
    {
        lbResults.Items.Add("Converting....");
 
        // This is the single call needed to convert a file
        resultItem = 
            PNConverter.ConvertFile(tbInputFile.Text,
                                    tbSaveFolder.Text,
                                    tbOutputFileName.Text,
                                    cbOverwriteExisting.Checked,
                                    false,
                                    false,
                                    cmbBoxFileTypes.Text,
                                    String.Empty,
                                    String.Empty,
                                    cbUseDCOM.Checked ? tbDCOMName.Text : String.Empty,

                                    String.Empty,
                                    String.Empty);
 
    }
    catch (Exception ex)
    {
        String errMsg = String.Format("An error occurred during conversion. {0}",
                                      ex.ToString()),
 
        lbResults.Items.Add(errMsg);
        MessageBox.Show(this, errMsg, this.Text);
    }
    finally
    {
      
        DisplayResultsItems(resultItem);
    }
}