title: codeigniter - convert html to pdf
body: <p>I have a little problem. I have html page and I want to convert to pdf. My index page has a list that will get to the database and click on "Download PDF", I put this list in a PDF file.</p>
  
  <p><strong>My controller:</strong></p>
  
  <pre><code>&lt;?php
  
      class pdf_c extends CI_Controller{
          function __construct() {
              parent::__construct();
              $this-&gt;load-&gt;helper(array('url', 'mediatutorialpdf'));
          }
  
      function index($download_pdf = ''){
             $ret = '';
             $ID = 1;
             $pdf_filename = 'user_info_'.$ID.'.pdf';
             $link_download = ($download_pdf == TRUE)?'':anchor(base_url().'index.php/true', 'Download PDF');
             $query = $this-&gt;db-&gt;query("SELECT * FROM `ci_pdf_user` WHERE `id` = '{$ID}' LIMIT 1");
             if($query-&gt;num_rows() &gt; 0)
             {
                  $user_info = $query-&gt;row_array();
             }
  
             $data_header = array(
                  'title' =&gt; 'Convert codeigniter to pdf'
             );
             $data_userinfo = array(
                  'user_info' =&gt; $user_info,
                  'link_download' =&gt; $link_download
             );
             $header = $this-&gt;load-&gt;view('header',$data_header, true);
             $user_info = $this-&gt;load-&gt;view('user_table', $data_userinfo, true);
             $footer = $this-&gt;load-&gt;view('footer','', true);
  
             $output = $header.$user_info.$footer;
             if($download_pdf == TRUE)
             {
                  generate_pdf($output, $pdf_filename);
             }
             else
             {
                  echo $output;
             }
        }
  }
  ?&gt;
  </code></pre>
  
  <p>The problem is when I click the button "Download PDF" should redirect me to the function index () and get the $ download_pdf = true. And so called generate_pdf function () that will generate the PDF. </p>
  
  <p>I think the problem is in the variable $ link_download, but can not solve the problem.</p>
  
  <p>Thanks</p>