1

I have to run the view in the background. Below code is displaying both views on the single page.

My project is just filling the form and after filling the form display the PDF in 300*400px in the image(only display the half pdf)

Explain What I am doing is, I have a registration form. After filling the registration form I have to call the URL in the background that URL will generate the PDF of it(PDF will not display to the student)then I have to pass the PDF URL which is generated to take the screenshot of it and screenshot of that image will display it in the view page.

This logic I am trying it. Or is there any other Idea?

public function generate_img(){
$session_stud_id=$this->session->userdata['student_session']['stud_id'];//student session id
$bg_link['bg_link']='index.php/Invoice/index/'.$session_stud_id;
$view_a=$this->load->view('test', $bg_link);//sending $bg_link to test view page and I have to run this view in the background
$req = curl_init();
curl_setopt($req, CURLOPT_URL,$view_a);
curl_exec($req);
$this->load->view('invoice_generate', $background_url_link);//What variable I have to use here? background URL i have to send it to other view page
}

Screenshot code

<?php 
echo $siteURL=base_url($background_url_link);
//call Google PageSpeed Insights API
$googlePagespeedData = file_get_contents("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=$siteURL&screenshot=true");
//decode json data
$googlePagespeedData = json_decode($googlePagespeedData, true);
//screenshot data
$screenshot = $googlePagespeedData['screenshot']['data'];
$screenshot = str_replace(array('_','-'),array('/','+'),$screenshot); 
//display screenshot image
echo "<img src=\"data:image/jpeg;base64,".$screenshot."\" />";
        ?>
Naren Verma
  • 2,205
  • 5
  • 38
  • 95
  • What do you mean by "run view in background"? – Xpleria Nov 08 '17 at 08:32
  • @NeilPatrao, Thanks for the reply, I mean run the view page in the background. Or is there any other idea? – Naren Verma Nov 08 '17 at 08:36
  • @NeilPatrao, Is it possible to take the screenshot of the URL like mydomain.com/index.php/invoice/index/10. In this URL my PDF is displaying and that is not a webpage – Naren Verma Nov 08 '17 at 08:42
  • See this https://web-capture.net/ and several other services online https://www.google.de/search?ei=TMoCWv_WHMLlaPyzpfAI&q=webpage+screenshot+free&oq=webpage+screenshot+&gs_l=psy-ab.1.4.0j0i67k1l2j0l2j0i67k1j0l4.43637.43637.0.45370.1.1.0.0.0.0.102.102.0j1.1.0..1..0...1.1.64.psy-ab..0.1.102....0.19TNesnVktM – Xpleria Nov 08 '17 at 09:12
  • Your answer could be here: https://stackoverflow.com/questions/467793/how-do-i-convert-a-pdf-document-to-a-preview-image-in-php – Xpleria Nov 08 '17 at 09:14
  • I don't want to enter the URL in the text box and clicked on submit. I just need it default take the URL and create the screenshot – Naren Verma Nov 08 '17 at 09:16
  • I don't want to use ImageMagick and GhostScript – Naren Verma Nov 08 '17 at 09:16

0 Answers0