pdfinfo = escapeshellarg($tools['pdfinfo']);
}
if (!empty($tools['pdftopng'])) {
$this->pdftopng = escapeshellarg($tools['pdftopng']);
}
if (!empty($tools['pdftoppm'])) {
$this->pdftoppm = escapeshellarg($tools['pdftoppm']);
}
$this->verbose = $verbose;
}
/**
* @return string pdfinfo version information (multiline information)
* @throws LogicException
* @throws RuntimeException
*/
public function getPdfinfoVersionInfo()
{
if (null === $this->pdfinfo) {
throw new LogicException('No path to pdfinfo. Provide it to ' . __CLASS__ . ' PHP class constructor.');
}
if (null === $this->pdfinfoVersionInfo) {
$exec = sprintf('%s -v 2>&1', $this->pdfinfo);
if ($this->verbose) {
echo $exec . PHP_EOL;
}
exec($exec, $output, $resultCode);
if (0 !== $resultCode && 99 !== $resultCode) {
throw new RuntimeException('Execution failed: ' . $exec);
}
$this->pdfinfoVersionInfo = implode(PHP_EOL, $output);
}
return $this->pdfinfoVersionInfo;
}
/**
* @return string pdftopng or pdftoppm version information (multiline information)
* @throws LogicException
* @throws RuntimeException
*/
public function getPdftopngVersionInfo()
{
$tool = $this->pdftopng ?: $this->pdftoppm;
if (null === $tool) {
throw new LogicException('No path to pdftopng not pdftoppm. Provide it to ' . __CLASS__ . ' PHP class constructor.');
}
if (null === $this->pdftopngVersionInfo) {
$exec = sprintf('%s -v 2>&1', $tool);
if ($this->verbose) {
echo $exec . PHP_EOL;
}
exec($exec, $output, $resultCode);
if (0 !== $resultCode && 99 !== $resultCode) {
throw new RuntimeException('Execution failed: ' . $exec);
}
$this->pdftopngVersionInfo = implode(PHP_EOL, $output);
}
return $this->pdftopngVersionInfo;
}
/**
* @param string $file Path of file to check
* @return bool
* @throws LogicException
*/
public function isPdf($file)
{
if (null === $this->pdfinfo) {
throw new LogicException('No path to pdfinfo. Provide it to ' . __CLASS__ . ' PHP class constructor.');
}
$exec = implode(' ', array(
$this->pdfinfo,
escapeshellarg($file)
));
if ($this->verbose) {
echo $exec . PHP_EOL;
}
exec($exec, $output, $resultCode);
if ($this->verbose) {
echo implode(PHP_EOL, $output) . PHP_EOL;
}
return (0 === $resultCode);
}
private function ensureFolder($path)
{
if (file_exists($path) && is_dir($path) && is_writable($path)) {
return;
}
if (!mkdir($path, 0775, true)) {
throw new RuntimeException('Could not create folder: ' . $path);
}
}
/**
* @param string $file The path of the PDF document to convert into PNG
* @param string $pngRoot The root of the generated PNG file names.
* Example: if $pngRoot = '/usr/home/TCPDF/compare_runs/my-root'
,
* the generated PNG files will be as follows:
*
/usr/home/TCPDF/compare_runs/my-root-0000001.png
,/usr/home/TCPDF/compare_runs/my-root-0000002.png
,