DocumentConverter.CanConvertTo Method
Definition
- Namespace
- GleamTech.DocumentUltimate
- Assembly
- GleamTech.DocumentUltimate.dll
CanConvertTo(DocumentFormat, DocumentEngine?)
Gets a value that indicates whether a direct conversion is possible to the specified format.
public bool CanConvertTo(DocumentFormat outputFormat, DocumentEngine? engine = null)
Parameters
outputFormatDocumentFormatThe format to convert to.
engineDocumentEngine?The document engine to force. If not specified, the best document engine will be chosen automatically according to the input and output formats.
Returns
- bool
true if a direct conversion is possible; otherwise, false.
Examples
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:
var documentConverter = new DocumentConverter(@"c:\SomeFolder\InputFile.docx");
// CanConvertTo 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.CanConvertTo(DocumentFormat.Pdf))
documentConverter.ConvertTo(DocumentFormat.Pdf);
// This check is same as above
if (documentConverter.CanConvertTo("OutputFile.pdf"))
documentConverter.ConvertTo(DocumentFormat.Pdf);
Dim documentConverter As New DocumentConverter("c:\SomeFolder\InputFile.docx")
' CanConvertTo 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.CanConvertTo(DocumentFormat.Pdf) Then
documentConverter.ConvertTo(DocumentFormat.Pdf)
End If
' This check is same as above
If documentConverter.CanConvertTo("OutputFile.pdf") Then
documentConverter.ConvertTo(DocumentFormat.Pdf)
End If
CanConvertTo(string, DocumentEngine?)
Gets a value that indicates whether a direct conversion is possible to the specified file.
public bool CanConvertTo(string outputFile, DocumentEngine? engine = null)
Parameters
outputFilestringThe file name or path or extension (with or without leading dot) of the converted document file.
engineDocumentEngine?The document engine to force. If not specified, the best document engine will be chosen automatically according to the input and output formats.
Returns
- bool
true if a direct conversion is possible; otherwise, false.
Examples
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:
var documentConverter = new DocumentConverter(@"c:\SomeFolder\InputFile.docx");
// CanConvertTo 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.CanConvertTo(DocumentFormat.Pdf))
documentConverter.ConvertTo(DocumentFormat.Pdf);
// This check is same as above
if (documentConverter.CanConvertTo("OutputFile.pdf"))
documentConverter.ConvertTo(DocumentFormat.Pdf);
Dim documentConverter As New DocumentConverter("c:\SomeFolder\InputFile.docx")
' CanConvertTo 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.CanConvertTo(DocumentFormat.Pdf) Then
documentConverter.ConvertTo(DocumentFormat.Pdf)
End If
' This check is same as above
If documentConverter.CanConvertTo("OutputFile.pdf") Then
documentConverter.ConvertTo(DocumentFormat.Pdf)
End If