Open the MPDF pdf file in an Ajax with Codeigniter

Asked

Viewed 330 times

3

Good afternoon,

I have an ajax code that takes the data from a page and goes to the Controller.Then this controller generates a pdf with this same data

AJAX code

function getPdf(id) {



            console.log(id);
            $.ajax({
                url: base_url+'painel/sistema/gerarContrato',
                type: 'POST',
                data: {id:id},
                dataType : 'json',
                success: function(data){
                    alert("alo");
                }
            });
        }

Controller

 public function gerarContrato() {

                $this->load->model('painel/sistema_model');

                $this->load->helper('funcoes');



                  $id = $this->input->post('id');


                $this->sistema_model->dadosContrato($id);

                 header('Content-Type: contrato/pdf');     


                //load the view and saved it into $html variable
                $html= $this->load->view('novo/contrato', $id, true);

                //this the the PDF filename that user will get to download
                $pdfFilePath = "contrato.pdf";

                $mpdf =$this->load->library('m_pdf','m_pdf');
                //load mPDF library
                $this->load->library('m_pdf','m_pdf');

               //generate the PDF from the given html
                $this->m_pdf->pdf->WriteHTML($html);

                //download it.
                $this->m_pdf->pdf->Output($pdfFilePath,'I');

            }

In inspecting element, it returns a strange code that I believe is PDF. How do I open this pdf with the data??

I am using mPDF;

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.