/** * Check and build the options for command line * * @param array $options The options to check * @return string The options in command line format * @access public * @static * @since 1.0.0 * @see ApiPrintOption::parseOption() */ public static function getOptions($options) { $options_cmdline = ''; foreach ($options as $option => $value) { $options_cmdline .= ApiPrintOption::parseOption($option, $value); } return $options_cmdline; }
/** * Convert HTML file to PDF * * @param string $url The URL (local or remote) to convert * @param string $pdf The absolute path where save the PDF * @param array $options The options table * @return mixed The absolute PDF file (with path) or false when convert failed * @access private * @since 1.0.0 */ private function printCmd($url, $pdf, $options = array()) { if (empty($url) === true || empty($pdf) === true) { throw new Exception('url and pdf can\'t be empty'); } if (file_exists(PRINT_BIN) === false) { throw new Exception('the convert program doesn\'t exists'); } if (file_exists($pdf) === true) { // On supprime l'ancien PDF avant unlink($pdf); } $command = escapeshellcmd(PRINT_BIN); // Ajout des options si necessaire $command .= ApiPrintOption::getOptions($options); $command .= ' ' . PRINT_CONSTANT_OPTIONS; $command .= ' ' . escapeshellarg($url) . ' ' . escapeshellarg($pdf); $res = exec($command, $output, $return); if ($return !== 0) { if (DEBUG === true) { throw new Exception('Error in command line : ' . $command . "\n" . $res . "\n" . print_r($output, true)); } return false; } else { return $pdf; } }