There are multiple target formats available when converting documents with GroupDocs.Conversion and you can always refer to supported file formats documentation for more details.
But what about getting possible conversions programmatically? For example, it could allow end-users to select the target format for a specific document or to display the complete list of supported formats.
Fortunately GroupDocs.Conversion API provides several ways to achieve this, so please check the available options below.
Get possible conversions for a specific document
When you need to know possible conversions for a provided source document you can do this by following the below steps:
Create an instance of the Converter class by passing the source document path as the constructor’s parameter.
The method will return the PossibleConversions collection with a complete list of possible conversions for the source document type.
The following code snippet shows how to get possible conversions of the source document:
using(Converterconverter=newConverter("sample.docx")){PossibleConversionsconversions=converter.GetPossibleConversions();Console.WriteLine("The source document is of type {0} and could be converted to:",conversions.Source.Extension);foreach(varconversioninconversions.All){Console.WriteLine("\t {0} as {1} conversion.",conversion.Format,conversion.IsPrimary?"primary":"secondary");}}
PossibleConversionsconversions=FluentConverter.Load("sample.docx").GetPossibleConversions();Console.WriteLine("The source document is of type {0} and could be converted to:",conversions.Source.Extension);foreach(varconversioninconversions.All){Console.WriteLine("\t {0} as {1} conversion.",conversion.Format,conversion.IsPrimary?"primary":"secondary");}
Get all available conversions
If it is required to programmatically obtain a collection of all supported conversions it is as easy as calling a static GetAllPossibleConversions method of the Converter class.
The following code snippet shows how to get all possible conversions:
varallPossibleConversions=Converter.GetAllPossibleConversions();foreach(varpossibleConversionsinallPossibleConversions){Console.WriteLine($"Source format: {possibleConversions.Source.Description}");foreach(varconversioninpossibleConversions.All){Console.WriteLine("\t...can be converted to {0} format as {1} conversion.",conversion.Format,conversion.IsPrimary?"primary":"secondary");}}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.