Я пытаюсь создать pdf-страницу веб-страницы с помощью Codeignitor, PhantomJS, и я использую ОС Linux. У меня есть файл phantom_helper с exec(). У меня есть коды от here. Я могу создать pdf-файл, когда я запустил phantomjs /var/www/PhantomJS/js/rasterize.js http://google.com /var/www/PhantomJS/pdf/Test.pdf
на оконном терминале . Здесь я добавлять коды, которые я имею,PhantomJS не работает с codeignator + exec()
Controller:
public function index()
{
$this->load->helper('phantomjs');
$this->load->helper('url');
$viewbox['generationStatus'] = 'PDF Generation successful';
$url = 'http://google.com';
$filename = strtotime(date('Y-m-d H:i:s')).'.pdf';
$resp = rasterize_wrapper($url,$filename);
$viewbox['filename'] = $resp;
if($resp == 0)
{
$viewbox['filename'] = '';
$viewbox['generationStatus'] = 'PDF Generation failed';
}
$this->load->view('welcome_message',$viewbox);
}
Phanthom_helper:
if (! function_exists('rasterize_wrapper'))
{
function rasterize_wrapper($url='', $output=''){
if($url=='' || $output=='')
{
show_error('URL or Output file name not defined correctly');
log_message('error','rasterize_wrapper: not initialized');
exit;
}
$url = escapeshellcmd($url);
exec('phantomjs '.realpath('js/rasterize.js').' '.$url.' '.realpath('pdf').'/'.$output,$output_status, $return_status);
if($return_status == '0'){ return $output;}
return 0;
}
}
Rasterize.js
var page = new WebPage();
if (phantom.args.length < 2 || phantom.args.length > 3) {
console.log('Usage: rasterize.js URL filename');
phantom.exit();
} else {
address = phantom.args[0];
output = phantom.args[1];
page.viewportSize = { width: 600, height: 600 };
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
} else {
window.setTimeout(function() {
page.render(output);
phantom.exit();
}, 200);
}
});
}
Извините, этот код работает на самом деле. Проблема была в том, что я использую Linux, поэтому мне нужно установить разрешение папки для папки сохранения PDF. Я установил его и получил pdf. Ty. – Sinto
Кто-нибудь знает, почему css и текст не отображаются во время работы на сервере. Я получаю все данные в локальной системе.? – Sinto