Get possible conversions

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Conversion MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-conversion -- dnx GroupDocs.Conversion.Mcp --yes
Folders, licensing and more →

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:

  1. Create an instance of the Converter class by passing the source document path as the constructor’s parameter.
  2. Call the getPossibleConversions method of the converter object.

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:

const sourceFile = "sample.docx";
const converter = new groupdocs.conversion.Converter(sourceFile);
const conversions = converter.getPossibleConversions();
console.log(
  util.format(
    '%s is of type %s and could be converted to:\n',
    inputFilePath,
    conversions.getSource().getExtension()
  )
);

const items = conversions.getAll();
console.log(items);

items.spliterator().getExactSizeIfKnown();

for (let i = 0; i < items.size(); i += 1) {
  const item = 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:

const sourceFile = "sample.docx";
const converter = new groupdocs.conversion.Converter(sourceFile);
const conversions = converter.getPossibleConversions();
console.log(
  util.format(
    'Source format: %s \n',
    conversions.getSource().getDescription()
  )
);

const items = conversions.getAll();
items.spliterator().getExactSizeIfKnown();

for (let i = 0; i < items.size(); i += 1) {
  const item = items.get(i)
  console.log(util.format('\t...can be converted to %s format as %s conversion.\n'), item.getFormat(),  item.isPrimary() ? 'primary' : 'secondary');
}