Ajout impression pdf
This commit is contained in:
parent
d523d94331
commit
bd84805c4c
@ -18,6 +18,9 @@ class PrintController extends Zend_Controller_Action
|
||||
$params['siret'] = $elements[2];
|
||||
$params['id'] = $elements[3];
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
return array(
|
||||
'controller' => $controller,
|
||||
@ -47,21 +50,56 @@ class PrintController extends Zend_Controller_Action
|
||||
}
|
||||
$fichier = str_replace('.pdf', '', $fichier);
|
||||
|
||||
//On Cherche le fichier html
|
||||
if (!file_exists(APPLICATION_PATH.'/../cache/pages/'.$fichier.'.html'))
|
||||
{
|
||||
echo 'Fichier introuvable';
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once 'wkhtmltopdf/wkhtmltopdf.php';
|
||||
$pdf = new wkhtmltopdf();
|
||||
$output_file = $pdf->exec(APPLICATION_PATH.'/../cache/pages/'.$fichier.'.html');
|
||||
|
||||
//Le fichier html n'est pas présent
|
||||
|
||||
$elements = $this->pageParams($fichier);
|
||||
$contoller = $elements['controller'];
|
||||
$action = $elements['action'];
|
||||
$params = $elements['params'];
|
||||
$params['print'] = 'pdf';
|
||||
|
||||
// Désactivation affichage
|
||||
$this->_helper->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
$content = $this->view->action($action, $controller, null, $params);
|
||||
//Envoi au navigateur
|
||||
if(!file_exists($output_file))
|
||||
{
|
||||
echo 'Impossible de générer le fichier PDF';
|
||||
exit;
|
||||
}
|
||||
|
||||
$dest = 'I';
|
||||
switch($dest)
|
||||
{
|
||||
case 'I': //Send to standard output
|
||||
header('Content-type: '.$content_type.'');
|
||||
header('Content-Length: '.filesize($output_file));
|
||||
header('Content-MD5: '.base64_encode(md5_file($output_file)));
|
||||
header('Content-Disposition: inline; filename="'.basename($output_file).'"');
|
||||
header('Cache-Control: private, max-age=0, must-revalidate');
|
||||
header('Pragma: public');
|
||||
ini_set('zlib.output_compression','0');
|
||||
echo file_get_contents($output_file);
|
||||
exit; // nécessaire pour être certain de ne pas envoyer de fichier corrompu
|
||||
|
||||
break;
|
||||
|
||||
case 'D': //Download file
|
||||
header('Content-Tranfer-Encoding: none');
|
||||
header('Content-Length: '.filesize($output_file));
|
||||
header('Content-MD5: '.base64_encode(md5_file($output_file)));
|
||||
header('Content-Type: application/octetstream; name="'.basename($output_file).'"');
|
||||
header('Content-Disposition: attachment; filename="'.basename($output_file).'"');
|
||||
header('Cache-Control: private, max-age=0, must-revalidate');
|
||||
header('Pragma: public');
|
||||
ini_set('zlib.output_compression','0');
|
||||
//header('Date: '.gmdate(DATE_RFC1123););
|
||||
//header('Expires: '.gmdate(DATE_RFC1123, time()+1));
|
||||
//header('Last-Modified: '.gmdate(DATE_RFC1123, filemtime($output_file)));
|
||||
echo file_get_contents($output_file);
|
||||
exit; // nécessaire pour être certain de ne pas envoyer de fichier corrompu
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,7 +121,9 @@ class PrintController extends Zend_Controller_Action
|
||||
|
||||
$fichier = str_replace('.html', '', $fichier);
|
||||
$elements = $this->pageParams($fichier);
|
||||
|
||||
if ($elements===false){
|
||||
exit;
|
||||
}
|
||||
$this->view->assign('controller', $elements['controller']);
|
||||
$this->view->assign('action', $elements['action']);
|
||||
$this->view->assign('params', $elements['params']);
|
||||
|
Loading…
x
Reference in New Issue
Block a user