EdgarsK's post in HTML + CSS konvertēšana uz PDF was marked as the answer
+- 2 sekundes un ir gatavs
personīgi uzturu python socket kurā palaižu kad vajag
public static function UrlToPdf($url, $target=null, $options=array(), $cooldown=2){
$request = '/usr/bin/xvfb-run --server-args="-screen 0, 1024x768x24" /usr/bin/wkhtmltopdf "%s" "%s"';
$args = '';
foreach($options as $name=>$value){
$args .= ($args?' ':'').$name.' '.$value;
}
$tmp = DOCROOT.'public/tmp/'.uniqid().'.'.uniqid();
while(is_file($tmp)){
$tmp = DOCROOT.'public/tmp/'.uniqid().'.'.uniqid();
}
$request = sprintf($request, $url, $tmp).($args?' '.$args:'');
$request .= '; chown spy:spy '.$tmp;
$request .= '; chmod 0777 '.$tmp;
$dump = Python_Api::Execute('127.0.0.1', $request);
sleep($cooldown);
if(!is_file($tmp)){
return '';
}
$data = file_get_contents($tmp);
@unlink($tmp);
if(!is_null($target)){
file_put_contents($target, $data);
}else{
return $data;
}
}
un izsaucu ar
$domain = 'http://www.bbc.co.uk';
$pdf = Python_Local::UrlToPdf($domain, null, array(
'-L' => 0,
'-T' => 0,
'-B' => 0,
'-R' => 0,
'--dpi' => 300,
'-s' => 'A4',
'-q' => ''
));
header("Content-type: application/pdf");
header("Content-Length: ".strlen($pdf));
header("Content-disposition: inline; filename=".get_domain_original_base_name($domain).'.pdf');
header("Accept-Ranges: ".strlen($pdf));
echo $pdf;
exit;