在视图中按钮以使用jquery-codeigniter-mpdf将表单另存为pdf

时间:2017-12-19 16:58:17

标签: jquery forms codeigniter button mpdf

我试图在视图中创建一个按钮以将表单(空)保存为pdf,我已经看过mpdf库,但我无法通过jquery将表单提供给驱动程序打印出来。

我真正想要的是打印一个表单的空模板,也许我不需要那么多混乱,也许我手工创建一个pdf表单并按下按钮下载它,但我的想法是用它来做网络上的不同形式,当你去打印时,你可以格式化它并且更优雅。

查看(例1):

a.sort(key=...)

控制器(例如)

    <p><a id="printform" class="btn btn-danger btn-sm"><b>Save Pdf </b><i class="fa fa-plus"></i></p>
<form action="" name="form1" id="form1" method="post" enctype="multipart/form-data">
      <div class="form-body">
        <div class="form-group">
          <label class="control-label col-md-3">Name <span class="ast">*</span></label> 
          <div class="col-md-9 margen">
            <input tabindex="1" id="name" name="name" type="text" class="form-control" />
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-md-3">Surname <span class="asterisco">*</span></label> 
          <div class="col-md-9 margen">
            <input tabindex="2" id="surname" name="surname" type="text" class="form-control" />
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-md-3">Adress <span class="ast">*</span></label> 
          <div class="col-md-9 margen">
            <input tabindex="4" id="adress" name="adress" type="text" class="form-control" />
          </div>
        </div>
        <center>
          <div class="form-group">  
            <input tabindex="6" type="submit" name="submit" class="btn btn-sm botonesmodales" value="Añadir" id="enviar" />
          </div>

    </form>

Jquery的

public function printpdf()
{
    $data = [];
    //load the view and saved it into $html variable
    $html=$this->load->view('example1', $data, true);

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

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

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

    //download it.
    $this->m_pdf->pdf->Output($pdfFilePath, "D");       
}

0 个答案:

没有答案