DocumentConverter.CanConvert(String, DocumentFormat, Nullable<DocumentEngine>) Method

Gets a value that indicates whether a direct conversion is possible from one document file to another format.

Definition

Namespace: GleamTech.DocumentUltimate
Assembly: GleamTech.DocumentUltimate (in GleamTech.DocumentUltimate.dll) Version: 7.6.5
C#
public static bool CanConvert(
	string inputFile,
	DocumentFormat outputFormat,
	DocumentEngine? engine = null
)

Parameters

inputFile  String
The file name or path or extension (with or without leading dot) of the document file to convert.
outputFormat  DocumentFormat
The format to convert to.
engine  Nullable<DocumentEngine>  (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

Boolean
true if a direct conversion is possible; otherwise, false.

Example

Use static CanConvert method to check beforehand if an input document can be directly converted another format:

C#
// CanConvert determines document format from the extension in file name.
// So it does not read the file to check if it's a valid Docx file.
if (DocumentConverter.CanConvert(@"c:\SomeFolder\InputFile.docx", DocumentFormat.Pdf))
    DocumentConverter.Convert(@"c:\SomeFolder\InputFile.docx", DocumentFormat.Pdf);

// This check is same as above
if (DocumentConverter.CanConvert(@"c:\SomeFolder\InputFile.docx", "OutputFile.pdf"))
    DocumentConverter.Convert(@"c:\SomeFolder\InputFile.docx", DocumentFormat.Pdf);

// This check is same as above
if (DocumentConverter.CanConvert(DocumentFormat.Docx, DocumentFormat.Pdf))
    DocumentConverter.Convert(@"c:\SomeFolder\InputFile.docx", DocumentFormat.Pdf);

See Also