Skip to content

Instantly share code, notes, and snippets.

@mohit-rocks
Created May 16, 2018 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohit-rocks/433b6abf7918f496a5768709b70e9994 to your computer and use it in GitHub Desktop.
Save mohit-rocks/433b6abf7918f496a5768709b70e9994 to your computer and use it in GitHub Desktop.
Sample implementation for Transcode method.
/**
* {@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