The convert method ConvertFile returns a PNConversionItem object that describes the original conversion request and contains an internal object, PNConversionResult which contains the results of the conversion request.
The methods ConvertFileList and ConvertFolder, which convert groups of files, return a list of PNConversionItem objects, one for every file found to convert.
It is this object that is queried to find out the following:
•The status of the conversion - success or failure?
•If the conversion failed, what errors occurred?
•What files were created?
To find out the status of a conversion you can call either one of two methods: HasErrors or GetConversionStatus.
HasErrors returns True if there were any errors during conversion for this item. All error message are available through the Errors collection in the ConversionResult property.
The method GetConversionStatus returns a PNConvertResultStatus conversion status for this item.
private void ReportStatusAndErrors(PNConversionItem result) { if (result != null) { String status = result.GetConversionStatus(); listBox1.Items.Add("Status:" + status););
if (result.HasErrors()) { if (result.ConversionResult.Errors.Count > 0) { listBox1.Items.Add("Errors occured during conversion: "); foreach (PNConversionResultError itemError in result.ConversionResult.Errors) { listBox1.Items.Add(itemError.Value); } } } } // results not null else { listBox1.Items.Add("Conversion module did not run."); } } |
The PNConversionResult object in each PNConversionItem object contains a collection listing all of the files created by this conversion request. The ConvertFile method returns a single PNConversionItem while the methods ConvertFileList and ConvertFolder will return a list of PNConversionItem objects, one for each file in the list or folder that was converted.
private void ListCreatedFiles(PNConversionItem result) { if (result != null) { listBox1.Items.Add("Conversion Item: " + result.SourceFilePath); listBox1.Items.Add("===========================================");
if (! result.HasErrors()) { if (result.ConversionResult.OutputFiles != null) { if (result.ConversionResult.OutputFiles.Count > 0) { listBox1.Items.Add("The following files where created: "); foreach (PNConversionResultOutputFile itemOutputFile in result.ConversionResult.OutputFiles) { listBox1.Items.Add(itemOutputFile.OutputFilePath); } } else { listBox1.Items.Add("No files were created."); } } } } } |