/** * Converts the given document. * * @param Transformist_Document $Document Document to convert. */ public function convert(Transformist_Document $Document) { $Input =& $Document->input(); $input = Transformist_Registry::extension($Input->type()); if (!empty($input)) { $input .= ':'; } $input .= $Input->path(); $Output =& $Document->output(); $output = Transformist_Registry::extension($Output->type()); if (!empty($output)) { $output .= ':'; } $output .= $Output->path(); $Convert = new Transformist_Command('convert'); $Convert->execute(array($input, $output)); }
/** * Converts the given document. * * @param Transformist_Document $Document Document to convert. */ public function convert(Transformist_Document $Document) { $Input =& $Document->input(); $Output =& $Document->output(); // The office command doesn't allow us to specify an output file name. // So here's the trick: we're creating a link to the input file, named // as the desired output file name, with a unique extension to ensure // that the link file name doesn't exists. // The we will pass the symlink to the office command, which will use // the link name as output file name. $inputPath = $Input->path(); $workaround = $Input->baseName() !== $Output->baseName(); if ($workaround) { $linkPath = $Output->dirPath() . DIRECTORY_SEPARATOR . $Output->baseName() . uniqid('.workaround-'); if (symlink($inputPath, $linkPath)) { $inputPath = $linkPath; } else { return; } } // $arguments = array(); if ($Output->type() == 'application/pdfa') { $arguments['-e'] = 'SelectPdfVersion=1'; } $format = Transformist_Registry::extension($Output->type()); if ($format) { $arguments['-f'] = $format; } $arguments += array('--output' => $Output->dirPath(), $inputPath); $Unoconv = new Transformist_Command('unoconv'); $R = $Unoconv->execute($arguments); // We don't need the symlink anymore. if ($workaround) { unlink($inputPath); } }
/** * */ public function testRegisterMulti() { Transformist_Registry::register(array('foo' => 'mime/foo', 'bar' => 'mime/bar')); $this->assertEquals('foo', Transformist_Registry::extension('mime/foo')); $this->assertEquals('bar', Transformist_Registry::extension('mime/bar')); }
/** * Lists documents based on the settings defined in setup( ). */ protected function _listDocuments() { if (empty($this->_pending)) { return; } foreach ($this->_pending['conversions'] as $in => $out) { if (!$this->_isMimeType($out)) { continue; } $mime = $this->_isMimeType($in); $pattern = $mime ? '*' : $in; $path = $this->_pending['input'] . DS . $pattern; $files = $this->_isGlobPattern($pattern) ? glob($path, GLOB_NOSORT) : array($path); if ($files) { foreach ($files as $file) { if ($mime) { $FileInfo = new Transformist_FileInfo($file); $type = false; try { $type = $FileInfo->type(); } catch (Transformist_Exception $exception) { //var_dump( $exception->getMessage( )); } if ($type !== $in) { continue; } } $Input = new Transformist_FileInfo($file, $mime ? $in : ''); $Output = new Transformist_FileInfo($this->_pending['output'] . DS . basename($file), $out); $Output->setExtension(Transformist_Registry::extension($out)); $this->addDocument(new Transformist_Document($Input, $Output)); } } } }