function perform($config_path) { /* todo: * check ghostscript capabilities of convert * render formula for test purpose * check pages of given pdf file */ $result = true; ?> <table> <tr> <th>Check</th> <th>Status</th> <th>Hint</th> </tr> <tr> <?php $result = $result && file_exists($config_path); ?> <td>Configuration present</td> <td class="<?php echo $result ? 'green' : 'red'; ?>"><?php echo $result ? "Yes":"No"; ?></td> <td> <?php if(!$result): ?> Run <a href="../setup/index.php">setup</a> first. <?php endif; ?> </td> </tr> <?php if ($result): ?> <tr> <?php include_once($config_path); $result = (!empty(MediabirdConfig::$pdftk_path) && MediabirdUtility::execExists(MediabirdConfig::$pdftk_path)) || (!empty(MediabirdConfig::$pdfinfo_path) && MediabirdUtility::execExists(MediabirdConfig::$pdfinfo_path)); ?> <td>PdfTk or pdfinfo accessible</td> <td class="<?php echo $result ? 'green' : 'red'; ?>"><?php echo $result ? "Yes":"No"; ?></td> <td> <?php if(!$result): ?> Install pdftk or pdfinfo. You might have to specify the path to pdftk or pdfinfo in the module options or config file. <?php endif; ?> </td> </tr> <tr> <?php $result = MediabirdUtility::execExists(MediabirdConfig::$latex_path); ?> <td>LaTeX accessible</td> <td class="<?php echo $result ? 'green' : 'red'; ?>"><?php echo $result ? "Yes":"No"; ?></td> <td> <?php if(!$result): ?> Install LaTeX and specify the path to the latex executable in the module options or config file. <?php endif; ?> </td> </tr> <tr> <?php $result = MediabirdUtility::execExists(MediabirdConfig::$convert_path); ?> <td>LaTeX helper DVIPNG accessible</td> <td class="<?php echo $result ? 'green' : 'red'; ?>"><?php echo $result ? "Yes":"No"; ?></td> <td> <?php if(!$result): ?> Install dvipng and specify the path to the dvipng executable in the module options or config file. <?php endif; ?> </td> </tr> <tr> <?php $result = MediabirdUtility::execExists(MediabirdConfig::$magic_path); ?> <td>ImageMagick accessible</td> <td class="<?php echo $result ? 'green' : 'red'; ?>"><?php echo $result ? "Yes":"No"; ?></td> <td> <?php if(!$result): ?> Install ImageMagick and specify the path to the convert executable in the module options or config file. <?php endif; ?> </td> </tr> <?php endif; ?> </table><?php }
/** * Returns the PDF header info * @param $filename File name * @param [$password] Password, optional * @return object */ function getPdfInfo($filename,$password=null) { $pdfInfoPath = MediabirdConfig::$pdfinfo_path; $pdfTkPath = MediabirdConfig::$pdftk_path; if(!file_exists($filename)) { return null; } $encInfo = ''; $info = (object)null; $info->encrypted = false; if(!empty($pdfInfoPath) && MediabirdUtility::execExists($pdfInfoPath)) { if(isset($password) && strlen($password)>0) { $info->encrypted = true; $encInfo = "-upw $password"; } $cmd=sprintf('%s -enc UTF-8 %s %s',escapeshellarg($pdfInfoPath),$encInfo,escapeshellarg($filename)); } else if(!empty($pdfTkPath) && MediabirdUtility::execExists($pdfTkPath)){ if(isset($password) && strlen($password)>0) { $info->encrypted = true; $encInfo = "input_pw $password"; } $cmd=sprintf('%s %s %s dump_data',escapeshellarg($pdfTkPath),escapeshellarg($filename),$encInfo); } else { return null; } $infoCachePath = MediabirdConfig::$cache_folder.md5($cmd); if(file_exists($infoCachePath) && is_readable($infoCachePath)) { $contents = file_get_contents($infoCachePath); $code = strlen($contents)>0 ? 0 : 1; $output = explode("\n",$contents); $lastLine = $output[count($output)-1]; } else { $lastLine = exec($cmd,$output,$code); if($code == 0 && empty($lastLine)) { return null; } else { file_put_contents($infoCachePath,join("\n",$output)); } } if($code == 0) { $info->pageCount = 0; $info->title = basename($filename); $nextTitle = false; foreach($output as $line) { if(preg_match("/(\w+)\s*\:\s*(.+)\s*$/",$line,$matches)) { if($matches[1]=="Pages" || $matches[1]=="NumberOfPages") { $info->pageCount = intval($matches[2]); } if($matches[1]=="Title" || $nextTitle) { $info->title = $matches[2]; } if($matches[1]=="Encrypted") { $info->encrypted = strpos($matches[2], "yes") === 0; } $nextTitle = $matches[1]=="InfoKey" && $matches[2]=="Title"; } } } else { $info->encrypted = true; } return $info; }