2011-05-18 09:43:24 +00:00
|
|
|
<?php
|
|
|
|
class wkhtmltopdf
|
|
|
|
{
|
2013-02-11 10:46:27 +00:00
|
|
|
protected $wkhtml;
|
2013-01-23 13:26:24 +00:00
|
|
|
|
2012-03-22 15:36:37 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
2012-11-05 15:33:01 +00:00
|
|
|
$c = Zend_Registry::get('config');
|
2013-02-11 10:48:40 +00:00
|
|
|
$this->wkhtml = $c->profil->wkhtmltopdf->path;
|
2012-03-22 15:36:37 +00:00
|
|
|
}
|
2013-01-23 13:26:24 +00:00
|
|
|
|
2012-03-22 15:36:37 +00:00
|
|
|
/**
|
|
|
|
* 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 = '')
|
|
|
|
{
|
2012-11-05 15:33:01 +00:00
|
|
|
$this->options[$name] = $value;
|
2012-03-22 15:36:37 +00:00
|
|
|
}
|
2013-01-23 13:26:24 +00:00
|
|
|
|
2011-05-18 09:43:24 +00:00
|
|
|
/**
|
|
|
|
* Imprime un fichier HTML en PDF avec l'utilitaire wkhtmltopdf
|
2012-03-22 15:36:37 +00:00
|
|
|
* @param string $fileIn
|
|
|
|
* @param string $fileOut
|
2011-05-18 09:43:24 +00:00
|
|
|
* @return string Nom du fichier
|
|
|
|
*/
|
2012-03-22 15:36:37 +00:00
|
|
|
public function exec($fileIn, $fileOut = '')
|
2011-05-18 09:43:24 +00:00
|
|
|
{
|
2012-03-22 15:36:37 +00:00
|
|
|
if (empty($fileOut)) {$fileOut = str_replace('.html', '.pdf', $fileIn); }
|
|
|
|
if(file_exists($fileOut)){ unlink($fileOut); }
|
|
|
|
|
2011-05-18 09:43:24 +00:00
|
|
|
$options = '--disable-internal-links';
|
2012-11-05 15:33:01 +00:00
|
|
|
if ( count($this->options) )
|
2011-05-18 09:43:24 +00:00
|
|
|
{
|
2012-11-05 15:33:01 +00:00
|
|
|
foreach ( $this->options as $name => $value )
|
2011-05-18 09:43:24 +00:00
|
|
|
{
|
2012-03-22 15:36:37 +00:00
|
|
|
$options.= ' --'.$name;
|
2012-11-05 15:33:01 +00:00
|
|
|
if ($value!= '') $options.= ' "'.$value.'"';
|
2012-03-22 15:36:37 +00:00
|
|
|
}
|
2012-11-05 15:33:01 +00:00
|
|
|
}
|
2013-01-23 13:26:24 +00:00
|
|
|
|
|
|
|
$cmd = $this->wkhtml.' '.$options.' "'.$fileIn.'" "'.$fileOut.'"';
|
2012-03-22 15:36:37 +00:00
|
|
|
exec( $cmd );
|
|
|
|
return $fileOut;
|
2011-05-18 09:43:24 +00:00
|
|
|
}
|
|
|
|
}
|