public function getConvertFileShell($source, &$destination)
 {
     $multipage = array('pdf');
     if (in_array($this->conversion[0], $multipage)) {
         if (!in_array($this->conversion[1], $multipage)) {
             $source .= '[0]';
         }
     }
     return array($this->cmd, Shell::argOptions($this->cmd_options, $this->configuration, 1), $source, $destination);
 }
 public function getConvertFileShell($source, &$destination)
 {
     $conf = $this->configuration;
     foreach ($this->cmd_options as $opt) {
         if ($opt['group'] === 'rasterize' && !isset($conf[$opt['name']])) {
             $conf[$opt['name']] = $opt['default'];
         }
     }
     $dimensions = $conf['output-width'] . '*' . $conf['output-height'];
     $zoom = 1;
     $shell = array($this->cmd, Shell::argOptions($this->cmd_options, $this->configuration, 1), realpath(__DIR__ . '/Resources/PhantomJs-rasterize.js'), strpos($source, '://') === FALSE ? 'file://' . $source : $source, $destination, $dimensions, $zoom);
     return $shell;
 }
 public function getConvertFileShell($source, &$destination)
 {
     $err = $this->getTempFile('err');
     return array($this->cmd, '--ps', $source, Shell::arg('>', Shell::SHELL_SAFE), $destination, Shell::arg('STDERR', Shell::SHELL_STDERR, $err));
 }
 public function getConvertFileShell($source, &$destination)
 {
     return array($this->cmd, Shell::argOptions($this->cmd_options, $this->configuration), $source, $destination);
 }
 public function getConvertFileShell($source, &$destination)
 {
     $shell = array($this->cmd, Shell::argOptions($this->cmd_options, $this->configuration, 1), Shell::arg('f', Shell::SHELL_ARG_BASIC_SGL, $this->conversion[1] === 'tex' ? 'tex' : 'ascii'), $source, Shell::arg('>', Shell::SHELL_SAFE), $destination);
     return $shell;
 }
 public function getConvertFileShell($source, &$destination)
 {
     $destination = str_replace('.' . $this->conversion[0], '.' . $this->conversion[1], $source);
     return array(Shell::arg('export HOME=' . escapeshellarg($this->settings['temp_dir']) . ';', Shell::SHELL_SAFE), $this->cmd, '--headless', '--convert-to', $this->conversion[1], '--outdir', $this->settings['temp_dir'], $source);
 }
 public function getConvertFileShell($source, &$destination)
 {
     $destination = str_replace('.' . $this->conversion[0], '.' . $this->conversion[1], $source);
     return array($this->cmd, Shell::arg('format', Shell::SHELL_ARG_BASIC_DBL_NOEQUAL, $this->conversion[1]), Shell::arg('outputpath', Shell::SHELL_ARG_BASIC_DBL_NOEQUAL, $this->settings['temp_dir']), $source);
 }
 public function getConvertFileShell($source, &$destination)
 {
     return array($this->cmd['pandoc'], Shell::argOptions($this->cmd_options, $this->configuration), $source, Shell::arg('o', Shell::SHELL_ARG_BASIC_SGL, $destination));
 }
 public function getConvertFileShell($source, &$destination)
 {
     return array("cat", $source, Shell::arg('|', Shell::SHELL_SAFE), $this->cmd, Shell::argOptions($this->cmd_options, $this->configuration, 1), Shell::arg('f', Shell::SHELL_ARG_BASIC_SGL, $destination), Shell::arg('-', Shell::SHELL_SAFE));
 }
Exemple #10
0
 public function convertFile($source, $destination)
 {
     // XMP Metadata was added in version 1.4 of the PDF format.
     // Thus, this setting can be ignored on older formats.
     // If left enabled, then pdftk will upgrade the version to 1.4.
     $remove_meta = isset($this->configuration['remove-metadata']) && $this->configuration['remove-metadata'];
     if ($remove_meta) {
         // Only remove metadata if this is a 1.4 PDF and there is some metadata
         $pdfVersion = file_get_contents($source, FALSE, NULL, 0, 10000);
         if (preg_match('@^%PDF-(\\d+\\.\\d+).*/(?:Metadata|M) @s', $pdfVersion, $arr)) {
             $pdfVersion = (double) $arr[1];
             if ($pdfVersion < 1.4) {
                 $remove_meta = FALSE;
             }
         } else {
             $remove_meta = FALSE;
         }
     }
     // One convert function is required to avoid recursion.
     $empty = $this->getTempFile('txt');
     $cleaned = $destination;
     if ($source === $destination || $remove_meta) {
         $cleaned = $this->getTempFile('pdf');
     }
     // pdftk source.pdf dump_data | sed 's/Value: .*/Value:/' > empty.txt
     $this->shell(array($this->cmd, $source, 'dump_data', Shell::arg('|', Shell::SHELL_SAFE), Shell::arg("sed 's/Value: .*/Value:/' > ", Shell::SHELL_SAFE), $empty));
     // pdftk source.pdf update_info empty.txt output destination.pdf flatten compress
     $cmd = array($this->cmd, $source, 'update_info', $empty, 'output', '-', 'flatten', $remove_meta ? 'uncompress' : 'compress');
     if (isset($this->configuration['remove-id']) && $this->configuration['remove-id']) {
         // /ID [<e8c87bb7a19df73c042da3b2a01dc7ff> <e8c87bb7a19df73c042da3b2a01dc7ff>]
         $cmd[] = Shell::arg(" | grep -va '^\\/ID \\[' ", Shell::SHELL_SAFE);
     }
     $cmd[] = Shell::arg('>', Shell::SHELL_SAFE);
     $cmd[] = $cleaned;
     $this->shell($cmd);
     // Clean up and finalize files.
     if ($remove_meta) {
         $temp = $this->getTempFile('pdf');
         $fp = fopen($cleaned, 'r');
         $fout = fopen($temp, 'w');
         $context = 'none';
         while (!feof($fp)) {
             // Go to the next object.
             $buffer = fgets($fp);
             if (!preg_match('@^\\d+ \\d+ obj@', $buffer)) {
                 fputs($fout, $buffer);
                 continue;
             }
             // Load the object def
             $def = array();
             while (!feof($fp)) {
                 $line = fgets($fp);
                 if (preg_match('@^/(.*?) (.*)$@', $line, $arr)) {
                     if ($arr[1] === 'Metadata') {
                         continue;
                     }
                     // Remove the date modified.
                     // This should specifically affect type = Annot (i.e., annotations)
                     if ($arr[1] === 'M') {
                         continue;
                     }
                     $def[$arr[1]] = trim($arr[2]);
                 }
                 $buffer .= $line;
                 if (substr($line, 0, 2) === '>>') {
                     break;
                 }
             }
             if ($def['Type'] === '/Metadata') {
                 // Remove it.
                 if (isset($def['Length'])) {
                     $len = (int) $def['Length'];
                     while ($len > 0 && !feof($fp)) {
                         $line = fgets($fp);
                         $len -= strlen($line);
                     }
                 }
                 while (substr($line, 0, 6) !== 'endobj' && !feof($fp)) {
                     $line = fgets($fp);
                 }
                 fputs($fout, $line);
             } else {
                 // Keep it.
                 fputs($fout, $buffer);
                 if (isset($def['Length'])) {
                     $len = (int) $def['Length'];
                     while ($len > 0 && !feof($fp)) {
                         $line = fgets($fp);
                         $len -= strlen($line);
                         fputs($fout, $line);
                     }
                 }
                 while (substr($line, 0, 6) !== 'endobj' && !feof($fp)) {
                     $line = fgets($fp);
                     fputs($fout, $line);
                 }
             }
         }
         fclose($fp);
         fclose($fout);
         $this->shell(array($this->cmd, $temp, 'update_info', $empty, 'output', $destination, 'flatten', 'compress'));
         unlink($temp);
         if ($cleaned !== $destination) {
             unlink($cleaned);
         }
     } elseif ($cleaned !== $destination) {
         rename($cleaned, $destination);
     }
     unlink($empty);
     return $this;
 }
 public function getConvertFileShell($source, &$destination)
 {
     return array($this->cmd, Shell::arg('form', Shell::SHELL_ARG_BASIC_DBL_NOEQUAL, 'from=' . $this->conversion[0]), Shell::arg('form', Shell::SHELL_ARG_BASIC_DBL_NOEQUAL, 'to=' . $this->conversion[1]), Shell::arg('form', Shell::SHELL_ARG_BASIC_DBL_NOEQUAL, 'input_files[]=@' . $source), 'http://c.docverter.com/convert', Shell::arg('>', Shell::SHELL_SAFE), $destination);
 }