DocumentConverterConvertTo(DocumentFormat, NullableDocumentEngine) Method

Converts the document file to another format. The converted file be generated in the same folder as the input file and the extension will be automatically determined from outputFormat.

Definition

Namespace: GleamTech.DocumentUltimate
Assembly: GleamTech.DocumentUltimate (in GleamTech.DocumentUltimate.dll) Version: 7.1.5
C#
public DocumentConverterResult ConvertTo(
	DocumentFormat outputFormat,
	DocumentEngine? engine = null
)

Parameters

outputFormat  DocumentFormat
The target format to convert the document file to.
engine  NullableDocumentEngine  (Optional)
The document engine to force. If not specified, the best document engine will be chosen automatically according to the input and output formats.

Return Value

DocumentConverterResult
A DocumentConverterResult object that contains the result of the document conversion such as output file paths.

Example

Create an instance of DocumentConverter class with an input document and call instance methods ConvertTo and CanConvertTo. This is useful especially when you want to convert the same input document to several output formats:

C#
var documentConverter = new DocumentConverter(@"c:\SomeFolder\InputFile.docx");

// Convert "c:\SomeFolder\InputFile.docx" to "c:\SomeFolder\InputFile.pdf"
documentConverter.ConvertTo(DocumentFormat.Pdf);

// Convert "c:\SomeFolder\InputFile.docx" to "c:\SomeFolder\OutputFile.pdf"
documentConverter.ConvertTo(@"c:\SomeFolder\OutputFile.pdf");

Convert and ConvertTo methods also returns an instance of DocumentConverterResult class which has some useful properties:

C#
var result = DocumentConverter.Convert(@"c:\SomeFolder\InputFile.docx", DocumentFormat.Jpg);

// result.ElapsedTime: Total elapsed time for the document conversion 
Console.WriteLine("Conversion took {0} milliseconds.", result.ElapsedTime.TotalMilliseconds);

// result.OutputFiles: A string array for the paths of the converted (output) document files. 
// When there is only one output file, the value will be a single item array.
// If the output is a directory (e.g. for DocumentFormat.Web format), 
// the string will have a trailing backslash (\).
Console.WriteLine("Conversion generated {0} output files:", result.OutputFiles.Length);
for (var i = 0; i < result.OutputFiles.Length; i++)
{
    Console.WriteLine("OutputFiles[{0}] -> {1}", i, result.OutputFiles[i]);
}

/*
    Conversion generated 3 output files:
    OutputFiles[0] -> InputFile-1.jpg
    OutputFiles[1] -> InputFile-2.jpg
    OutputFiles[2] -> InputFile-3.jpg
**/

See Also