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:
constsourceFile="sample.docx";constconverter=newgroupdocs.conversion.Converter(sourceFile);constconversions=converter.getPossibleConversions();console.log(util.format('%s is of type %s and could be converted to:\n',inputFilePath,conversions.getSource().getExtension()));constitems=conversions.getAll();console.log(items);items.spliterator().getExactSizeIfKnown();for(leti=0;i<items.size();i+=1){constitem=items.get(i);console.log(`\t ${item.getFormat().getExtension()} as ${item.isPrimary()?'primary':'secondary'} conversion.\n`);}
Get all available conversions
If it is required to programmatically obtain a collection of all supported conversions it is as easy as calling the getAllPossibleConversions method of the Converter class.
The following code snippet shows how to get all possible conversions:
constsourceFile="sample.docx";constconverter=newgroupdocs.conversion.Converter(sourceFile);constconversions=converter.getPossibleConversions();console.log(util.format('Source format: %s \n',conversions.getSource().getDescription()));constitems=conversions.getAll();items.spliterator().getExactSizeIfKnown();for(leti=0;i<items.size();i+=1){constitem=items.get(i)console.log(util.format('\t...can be converted to %s format as %s conversion.\n'),item.getFormat(),item.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.