66 lines
1.8 KiB
PHP
66 lines
1.8 KiB
PHP
<?php
|
|
class wkhtmltopdf
|
|
{
|
|
protected $pathWkhtml;
|
|
protected $pathIn = '';
|
|
protected $pathOut = '';
|
|
protected $options = array();
|
|
protected $arch = 'amd64';
|
|
|
|
public function __construct()
|
|
{
|
|
$c = Zend_Registry::get('config');
|
|
$this->wkthml = $c->profil->wkhtmltopdf->path;
|
|
}
|
|
|
|
/**
|
|
* Défini les options supplémentaires à l'execution de wkhtmltopdf
|
|
* -n, --disable-javascript Do not allow webpages to run javascript.
|
|
* --disable-internal-links Do no make local links
|
|
* --disable-external-links Do no make links to remote web pages
|
|
* --user-style-sheet <url> Specify a user style sheet, to load with every page.
|
|
* --print-media-type Use print media-type instead of screen.
|
|
* --header-left|right
|
|
* @param string $name
|
|
* @param string $value
|
|
*/
|
|
public function setOptions($name, $value = '')
|
|
{
|
|
$this->options[$name] = $value;
|
|
}
|
|
|
|
/**
|
|
* Imprime un fichier HTML en PDF avec l'utilitaire wkhtmltopdf
|
|
* @param string $fileIn
|
|
* @param string $fileOut
|
|
* @return string Nom du fichier
|
|
*/
|
|
public function exec($fileIn, $fileOut = '')
|
|
{
|
|
if (empty($fileOut)) {$fileOut = str_replace('.html', '.pdf', $fileIn); }
|
|
if(file_exists($fileOut)){ unlink($fileOut); }
|
|
|
|
$options = '--disable-internal-links';
|
|
if ( count($this->options) )
|
|
{
|
|
foreach ( $this->options as $name => $value )
|
|
{
|
|
$options.= ' --'.$name;
|
|
if ($value!= '') $options.= ' "'.$value.'"';
|
|
}
|
|
}
|
|
|
|
if ( stristr(PHP_OS, 'WIN') ) {
|
|
$wkhtmltopdf = 'windows/wkhtmltopdf.exe';
|
|
} else {
|
|
switch ( $this->arch ) {
|
|
default:
|
|
case 'amd64': $wkhtmltopdf = 'linux/wkhtmltopdf-amd64'; break;
|
|
case 'i386': $wkhtmltopdf = 'linux/wkhtmltopdf-i386'; break;
|
|
}
|
|
}
|
|
$cmd = $this->wkhtml.' '.$options.' "'.$fileIn.'" "'.$fileOut.'"';
|
|
exec( $cmd );
|
|
return $fileOut;
|
|
}
|
|
} |