GroupDocs.Conversion offers several methods to retrieve possible conversions:
Converter.get_all_possible_conversions(): Retrieves all available primary and secondary conversions for every supported file type.
Converter.get_possible_conversions_by_extension(extension: str): Retrieves possible conversions for a specific file extension, e.g., "docx".
converter.get_possible_conversions(): Retrieves possible conversions for the currently loaded file.
Types of Conversions
Primary Conversion: A direct conversion from one format to another, providing higher quality and better performance.
Secondary Conversion: An indirect conversion that requires the source file to be first converted to an intermediate format before reaching the final format.
Example 1: Get All Possible Conversions
The following example demonstrates how to retrieve and display all primary and secondary conversions for every supported file type.
fromgroupdocs.conversionimportConverter# GroupDocs.Conversion supports 150+ source formats; print the first N# to keep the console output readable. Raise or remove the limit to see# every source format.SAMPLE_LIMIT=3defget_all_possible_conversions():# Get all possible conversions for every supported source formatall_possible_conversions=list(Converter.get_all_possible_conversions())print(f"Total supported source formats: {len(all_possible_conversions)}")print(f"Showing the first {SAMPLE_LIMIT} as a sample.")print()forpossible_conversioninall_possible_conversions[:SAMPLE_LIMIT]:# Collect primary / secondary target extensions for this sourceprimary_conversions=[c.format.extensionforcinpossible_conversion.allifc.is_primary]secondary_conversions=[c.format.extensionforcinpossible_conversion.allifnotc.is_primary]# Print the source format and its target extensionsprint(f"Source format: {possible_conversion.source.description}")print(f" Primary target formats ({len(primary_conversions)}): {primary_conversions}")print(f" Secondary target formats ({len(secondary_conversions)}): {secondary_conversions}")print()if__name__=="__main__":get_all_possible_conversions()
Example 2: Get Possible Conversions by File Extension
The following example demonstrates how to retrieve and display possible conversions for the “docx” extension, which corresponds to a Microsoft Word Open XML Document.
fromgroupdocs.conversionimportConverterdefget_all_possible_conversions_by_file_extension():# Get all possible conversions for a specific extensionpossible_conversion=Converter.get_possible_conversions_by_extension("docx")# Filter primary conversions (use .extension for a clean string)primary_conversions=[conversion.format.extensionforconversioninpossible_conversion.allifconversion.is_primary]# Filter secondary conversionssecondary_conversions=[conversion.format.extensionforconversioninpossible_conversion.allifnotconversion.is_primary]# Print out the source format and its conversionsprint(f" **Source format**: {possible_conversion.source.description}")print(f" - **Primary conversions**: {primary_conversions}")print(f" - **Secondary conversions**: {secondary_conversions}")print()if__name__=="__main__":get_all_possible_conversions_by_file_extension()
Example 3: Get Possible Conversions for Current File
The following example demonstrates how to retrieve and display possible conversions for a file passed to the Converter class constructor.
fromgroupdocs.conversionimportConverterdefget_all_possible_conversions_for_current_file():withConverter("./cost-analysis.xlsx")asconverter:# Get possible conversions for the loaded documentpossible_conversion=converter.get_possible_conversions()# Filter primary conversions (use .extension for a clean string)primary_conversions=[conversion.format.extensionforconversioninpossible_conversion.allifconversion.is_primary]# Filter secondary conversionssecondary_conversions=[conversion.format.extensionforconversioninpossible_conversion.allifnotconversion.is_primary]# Print out the source format and its conversionsprint(f" **Source format**: {possible_conversion.source.description}")print(f" - **Primary conversions**: {primary_conversions}")print(f" - **Secondary conversions**: {secondary_conversions}")print()if__name__=="__main__":get_all_possible_conversions_for_current_file()