【问题标题】:How can give name for generate pdf using mpdf codeigniter如何使用 mpdf codeigniter 为生成 pdf 命名
【发布时间】:2016-03-02 13:45:28
【问题描述】:

如果有人知道这一点,请帮助我。如何为 pdf 命名。 我使用 mpdf codeigniter 生成了 pdf。单击按钮即可查看pdf。但是如何为该pdf命名?它在 pdf 的顶部显示 1。我如何为该 pdf 命名? 我的控制器

public function viewpdf($key,$option) {

     if($option=='1')
    {
        $searchdata['fetchproduct']=$this->b2bproduct_model->fetch_productdata1($key);

    }
    if($option=='2')
    {
        $searchdata['fetchproduct']=$this->b2bproduct_model->fetch_productdata2($key); 
    }
    if($option=='3')
    {
       $searchdata['fetchproduct']=$this->b2bproduct_model->fetch_productdata3($key); 

    }

    $html=$this->load->view('moderator/pdf_data', $searchdata,true);

        //this the the PDF filename that user will get to download
        $pdfFilePath = "shany.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, "I");   
      }

【问题讨论】:

  • 请显示一些(真实的)代码。
  • @phaberest 我把代码放在这里

标签: codeigniter codeigniter-2 mpdf codeigniter-3


【解决方案1】:

使用此代码。

$mpdf=new mPDF();
$mpdf->SetTitle('My Title');
$mpdf->WriteHTML('<p>Hallo World</p>');
$mpdf->Output('filename.pdf');

设置文档的标题。查看 PDF 文件时,标题显示在 Adob​​e Reader 屏幕的顶部

【讨论】:

    【解决方案2】:

    使用如下代码

    public function mypdf() {     
       $this->load->library('pdf');     
       $pdf = $this->pdf->load();     
       $html=$this->load->view('welcome_message',null,true);
       $pdf->WriteHTML($html);      
       // write the HTML into the PDF     
       $output = 'your_given_name.pdf'; //You can give a name of your generated pdf file or you can create it auto on timestamp by using $output = time().'.pdf'.
       $pdf->Output("$output", 'I');     
    }
    

    如果您将数据发送到查看页面,则将第 4 行中的 variable 替换为 null

    更多详情请看here的教程。

    如果您对 DOMPDF 感兴趣,请查看here

    【讨论】:

      猜你喜欢
      • 2014-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-11
      • 2019-10-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多