/** * Generates PDF preview image and saves it. * @param string $pdfFilePath full path to pdf file. * @param string $destImagePath full path of image file that must be saved. * @throws InvalidParamException if cannot write file. */ public static function savePreview($pdfFilePath, $destImagePath) { $decodedDestImagePath = FileSystemHelper::decodeFilename($destImagePath); if ($decodedDestImagePath === false) { $extension = null; } else { $extension = FileSystemHelper::extension($decodedDestImagePath); $extension = FileSystemHelper::encodeFilename($extension); } $content = static::getPreview($pdfFilePath, $extension); if (false === @file_put_contents($destImagePath, $content)) { throw new InvalidParamException("Cannot save file: {$destImagePath}"); } }