Guest User

Untitled

a guest
May 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. public function index()
  2. {
  3. $this->load->helper('phantomjs');
  4. $this->load->helper('url');
  5. $viewbox['generationStatus'] = 'PDF Generation successful';
  6. $url = 'http://google.com';
  7. $filename = strtotime(date('Y-m-d H:i:s')).'.pdf';
  8. $resp = rasterize_wrapper($url,$filename);
  9. $viewbox['filename'] = $resp;
  10. if($resp == 0)
  11. {
  12. $viewbox['filename'] = '';
  13. $viewbox['generationStatus'] = 'PDF Generation failed';
  14. }
  15. $this->load->view('welcome_message',$viewbox);
  16. }
  17.  
  18. if ( ! function_exists('rasterize_wrapper'))
  19. {
  20. function rasterize_wrapper($url='', $output=''){
  21. if($url=='' || $output=='')
  22. {
  23. show_error('URL or Output file name not defined correctly');
  24. log_message('error','rasterize_wrapper: not initialized');
  25. exit;
  26. }
  27. $url = escapeshellcmd($url);
  28. exec('phantomjs '.realpath('js/rasterize.js').' '.$url.' '.realpath('pdf').'/'.$output,$output_status, $return_status);
  29. if($return_status == '0'){ return $output;}
  30. return 0;
  31. }
  32. }
  33.  
  34. var page = new WebPage();
  35. if (phantom.args.length < 2 || phantom.args.length > 3) {
  36. console.log('Usage: rasterize.js URL filename');
  37. phantom.exit();
  38. } else {
  39. address = phantom.args[0];
  40.  
  41. output = phantom.args[1];
  42. page.viewportSize = { width: 600, height: 600 };
  43. page.open(address, function (status) {
  44. if (status !== 'success') {
  45. console.log('Unable to load the address!');
  46. } else {
  47. window.setTimeout(function () {
  48. page.render(output);
  49. phantom.exit();
  50. }, 200);
  51. }
  52. });
  53. }
Add Comment
Please, Sign In to add comment