0

Expected requirement - when user clicks button ajax will be call to controller where pdf will generate and generated pdf will gets downloaded on user's system.

Actual Scene - i able to create pdf using fpdf file and saved in folder and used force download function but nothing happend. here's my code:

Controller :

    $this->load->helper('download');
    $this->load->library('myfpdf');
    $this->load->view('pdf/namewise_report',[]);
    $link = base_url().'uploads/pdfs/namewise.pdf';
    force_download($link, NULL);

pdf/namewise_report.php (last line)

    $this->myfpdf->Output('uploads/pdfs/namewise.pdf', "F");

is there anything to add in ajax success response

Manjiri Parab
  • 131
  • 1
  • 14
  • Have you looked at this? :) https://stackoverflow.com/questions/13209897/using-ajax-and-jquery-to-create-pdf-using-fpdf – Jonas Borneland Nov 20 '18 at 07:20
  • Another option is to try with 'file_get_contents(the url here)' instead of AJAX; – Jonas Borneland Nov 20 '18 at 07:22
  • simple, don't use ajax for this. no reason to. simple url to download controller will force download the pdf to the computer without altering the current page/causing refresh/new page opening .etc. the best way to think about ajax is like a background process worker, it is the "active" page so to speak so nothing will happen. – Alex Nov 20 '18 at 08:37
  • @Alex actually i have to use ajax because whatever parameters passing based on that pdf will generate... have to use ajax. i also tried file get contents and force download(name, content) but didnt work. – Manjiri Parab Nov 21 '18 at 03:35
  • 1
    sorry but its just the way it is: https://stackoverflow.com/questions/4750461/xmlhttprequest-to-open-pdf-in-browser/4750685#4750685 ... that being said, there was a time when ajax never existed... so *no* you don't **have** to use ajax. find another way to pass your params. – Alex Nov 21 '18 at 08:49
  • @Alex Ok Thanks for help – Manjiri Parab Nov 21 '18 at 16:32

0 Answers0