Created
May 16, 2018 14:26
-
-
Save mohit-rocks/433b6abf7918f496a5768709b70e9994 to your computer and use it in GitHub Desktop.
Sample implementation for Transcode method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* {@inheritdoc} | |
*/ | |
public function transcode($source_path, $destination_path, $destination_uri) { | |
$unoconv_config = $this->configFactory->get('unoconv_service.unoconvconfig'); | |
try { | |
$unoconv = Unoconv::create(array( | |
'timeout' => $unoconv_config->get('timeout'), | |
'unoconv.binaries' => $unoconv_config->get('binaries_path'), | |
)); | |
$unoconv->transcode($source_path, 'pdf', $destination_path); | |
} catch (ExecutionFailureException $exception) { | |
throw new RuntimeException( | |
t('Unoconv failed to transcode file'), $exception->getCode(), $exception); | |
} | |
// Saving new converted preview pdf file and attach it to media entity. | |
$data = file_get_contents($destination_path); | |
$preview_file = file_save_data($data, $destination_uri, FILE_EXISTS_RENAME); | |
return $preview_file; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment