45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
class wkhtmltopdf
|
|
{
|
|
public function __construct(){}
|
|
|
|
/**
|
|
* Imprime un fichier HTML en PDF avec l'utilitaire wkhtmltopdf
|
|
* @param $file
|
|
* @return string Nom du fichier
|
|
*/
|
|
function exec($file)
|
|
{
|
|
$date = date('d/m/Y H:i:s');
|
|
$output_file = str_replace('.html', '.pdf', $file);
|
|
if(file_exists($output_file)){ unlink($output_file); }
|
|
/*
|
|
* -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
|
|
*/
|
|
$options = '--disable-internal-links';
|
|
$options.= ' --footer-right "Page [page] sur [toPage]"';
|
|
$options.= ' --header-right "'.$date.'"';
|
|
if (stristr(PHP_OS, 'WIN'))
|
|
{
|
|
$wkhtmltopdf = 'windows/wkhtmltopdf.exe';
|
|
}
|
|
else
|
|
{
|
|
switch(WKHTMLTOPDF_ARCH)
|
|
{
|
|
case 'amd64': $wkhtmltopdf = 'linux/wkhtmltopdf-amd64'; break;
|
|
default:
|
|
case 'i386': $wkhtmltopdf = 'linux/wkhtmltopdf-i386'; break;
|
|
}
|
|
}
|
|
exec( realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR.
|
|
$wkhtmltopdf.' '.$options.' "'.$file.'" "'.$output_file.'"');
|
|
return $output_file;
|
|
}
|
|
|
|
} |