public function getPreviewFromPdf(FilesModel $file, int $page = 0): FilesModel
    {
        $strippedName = str_replace('.'.$file->extension, '', $file->name);
        $previewFileName = 'preview-'.$strippedName.'.'.static::FILE_UTIL_CONVERT_FILE_TYPE;
        $folder = str_replace($file->name, '', $file->path);
        $target = $folder.\DIRECTORY_SEPARATOR.$previewFileName;

        // ghostscript
        /** @var Transcoder $transcoder */
        $transcoder = $this->framework->getAdapter(Transcoder::class)->create();
        $transcoder->toImage($file->path, $target);

        // get all created images
        $folderFiles = scandir($folder);
        $pdfPreviewFiles = [];
        $needle = '/preview-'.$strippedName.'*\.'.static::FILE_UTIL_CONVERT_FILE_TYPE.'/';

        foreach ($folderFiles as $file) {
            if (!preg_match($needle, $file)) {
                continue;
            }

            $pdfPreviewFiles[] = $file;
        }

        $preview = null;

        foreach ($pdfPreviewFiles as $key => $value) {
            if ($page != $key && file_exists($value)) {
                unlink($value);

                continue;
            }

            $preview = $value;
        }

        if (null === ($previewFile = $this->framework->getAdapter(FilesModel::class)->findByPath($preview))) {
            $previewFile = $this->framework->getAdapter(Dbafs::class)->addResource($folder.\DIRECTORY_SEPARATOR.$preview);
        }

        return $previewFile;
    }