Utililty function to convert file extension to ImageFileType enum

Is there any method to find ImageFileType from file extension?

Hi there,

Thanks for your inquriy. You may use may use Aspose.Imaging to detect image file format and use ImageFileType accordingly. However if there is any difference in your requirements and my understanding then please share some more details along with sample code here, so we will look into it and will guide you accordingly.

Image file format detection using Aspose.Imaging:

int imageType = (int)Aspose.Imaging.Image.GetFileFormat(“Test.PNG”);

String image = null;

switch (imageType) {

case 0: image = “Undefined”;


case 1: image = “Custom”;


case 2: image = “BMP”;


case 4: image = “GIF”;


case 8: image = “JPEG”;


case 16: image = “PNG”;


case 32: image = “TIFF”;


case 64: image = “PSD”;


case 128: image = “DXF”;


case 256: image = “DWG”;


case 512: image = “Jpeg2000”;


case 1024: image = “Djvu”;




Please feel free to contact us for any further assistance.

Best Regards,

I use Aspose.Pdf and I can't use Aspose.Imaging in my project.
I have array of images with different type and I want to convert this images to separate pdf in a loop.
I use bellow sample code to do this, But I don't know how to get Aspose.Pdf.Generator.ImageFileType from file extensions.

How to Convert an Image to PDF

Hi Freydoon,

Thanks for sharing the details.

The above stated approach is an old legacy approach of Image to PDF conversion where its required to specify the type of input image. However we recommend using new Document Object Model of Aspose.Pdf namespace for Image to PDF conversion, which do not require the image type but in fact it automatically determines the image type and performs the conversion. For more information, please visit Convert an Image to PDF

In case you encounter any issue, please share the input files, so that we can further test the scenario in our environment.

Thanks for the prompt reply.

This was exactly what I needed.

Best regards.

Hi Freydoon,

Thanks for the acknowledgement.

We are glad to hear that your problem is resolved. Please continue using our API’s and in the event of any further query, please feel free to contact.