简体   繁体   中英

How to render content on dompdf after ajax call using codeigniter?

<script>
    $(document).on("click",".pdf_sheet", function(){
        var subjectID = $("#subjectID").val();
        var session = $("#SessionFrom").val()+"-"+$("#SessionTo").val();
        var courseID = $("#classesID").val();
        var yearsOrSemester = $("#yearSemesterID").val();
        $.ajax({
            type: 'POST',
            url: "<?=base_url('student/sheetPDF')?>",
            data: {"subjectID":subjectID,"session":session,"courseID":courseID,"yearsOrSemester":yearsOrSemester},
            cache: false,
            success: function(data) {
            }
        });
    });
</script>

Controller:

function sheetPDF()
{
    $subjectID = $this->input->post('subjectID');
    $session = $this->input->post('session');
    $courseID = $this->input->post('courseID');
    $yearsOrSemester = $this->input->post('yearsOrSemester'); 
    $data['subjectID'] = $subjectID;
    $data['session'] = $session;
    $data['courseID'] = $courseID;
    $data['yearsOrSemester'] = $yearsOrSemester;
    $data['award'] = $this->classes->award($subjectID,$session,$courseID,$yearsOrSemester);
    $this->load->view('sheet',$data);
    $html = $this->output->get_output();
    $this->load->library('pdf');
    $this->dompdf->loadHtml($html);
    $this->dompdf->render();
    $this->dompdf->stream("Awardsheet.pdf", array("Attachment"=>1));
}

I am using DOMPdf to convert html to pdf file. Now, What is happening when I click on pdf_sheet class then content are showing but not rendering on html. So, How can I show view file on pdf file? So, How can I do this? Please help me.

Thank You

Ajax call doesn't render application/pdf. Instead of ajax use web form to render PDF.

$(document).on("click",".pdf_sheet", function(){
    var subjectID = $("#subjectID").val();
    var session = $("#SessionFrom").val()+"-"+$("#SessionTo").val();
    var courseID = $("#classesID").val();
    var yearsOrSemester = $("#yearSemesterID").val();
    var form = '<form id="static_form" action="<?=base_url('student/sheetPDF')?>"    method="post">';
    form += '<input type="hidden" name="subjectID" value="' + subjectID + '">';
    form += '<input type="hidden" name="session" value="' + session + '">';
    form += '<input type="hidden" name="courseID" value="' + courseID + '">';
    form += '<input type="hidden" name="yearsOrSemester" value="' + yearsOrSemester+ '">';
    form += '</form>';
    $('body').append(form);
    $('#static_form').submit();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM