Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- 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;
- }
- }
- 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);
- }
- });
- }
Add Comment
Please, Sign In to add comment