get_file_format method

get_file_format

Gets the file format.

Returns

The determined file format.

def get_file_format(self, file_path):
    ...
ParameterTypeDescription
file_pathstrThe file path.

Remarks

The file format determined does not mean that the specified image may be loaded. Use one of the CanLoad method overloads to determine whether file may be loaded.

Example

Determines whether file is a DWG drawing

from aspose.cad import FileFormat, Image

fileFormat = Image.get_file_format("file.dwg")
if fileFormat >= FileFormat.CAD_R010 and fileFormat <= FileFormat.CAD_R2010:
    print("This is a DWG drawing")

get_file_format

Gets the file format.

Returns

The determined file format.

def get_file_format(self, stream):
    ...
ParameterTypeDescription
streamio.RawIOBaseThe stream.

Remarks

The file format determined does not mean that the specified image may be loaded. Use one of the CanLoad method overloads to determine whether stream may be loaded.

Example

Determines whether a stream contains a DXF drawing

from aspose.cad import FileFormat, Image

with open("file.dxf", "rb") as f:
    fileFormat = Image.get_file_format(f)
    if fileFormat >= FileFormat.DXF_CAD_R010 and fileFormat <= FileFormat.DXF_CAD_R2010:
        print("This is a DXF drawing")

See Also