如何在CI中保存由CI中的DOMPDF库生成的动态生成PDF文件

时间:2019-05-03 06:41:12

标签: codeigniter

如何将PDF文件保存在通过单击按钮按钮生成的特定文件夹中,以及如何使用CI中的DOMPDF库在Ci中动态生成PDF文件。实际上,我的问题只是成功地生成了文件,但我无法将文件存储在特定的文件夹中..请告诉我如何将文件保存在特定的文件夹中??

<?php

$html = "<table border='1' width='100%' style='border-collapse: collapse;'>
        <tr>
            <th>Username</th><th>Email</th>
        </tr>
        <tr>
            <td>yssyogesh</td>
            <td>yssyogesh@makitweb.com</td>
        </tr>
        <tr>
            <td>sonarika</td>
            <td>sonarika@gmail.com</td>
        </tr>
        <tr>
            <td>vishal</td>
            <td>vishal@gmail.com</td>
        </tr>
        </table>";
 $output = '<table width="100%" style="width:100%;  border: 1px solid black;
  border-collapse: collapse;">';
 $output .='<tr style="width:100%;  border: 1px solid black;
                    border-collapse: collapse;">
                   <td style="text-align:center; border: 1px solid black; border-collapse: collapse;" colspan="2"> Smart Citizen</td>
                   </tr>';
  foreach($update_data->result() as $row)
  {

   $output .= '

                    <tr style="width:100%;  border: 1px solid black;
                    border-collapse: collapse;">
                    <td style="width:30%;  border: 1px solid black;
                    border-collapse: collapse;" > Fullfilment Id </td>
                    <td style=" border: 1px solid black;
                   border-collapse: collapse;" >'.strtoupper(substr($row->department_name,0,2)).$row->redeem_id.'</td>
                    </tr>

                     <tr style="width:100%;  border: 1px solid black;
                     border-collapse: collapse;" > 
                     <td style="width:30%;  border: 1px solid black;
                     border-collapse: collapse;"> Department Name </td>
                     <td style=" border: 1px solid black;
                     border-collapse: collapse;">'.$row->department_name.'</td>
                    </tr>  

                     <tr  style="width:100%;  border: 1px solid black;
                      border-collapse: collapse;"> 
                    <td style="width:30%;  border: 1px solid black;
                     border-collapse: collapse;" > Department Mobile Number </td>
                    <td   style=" border: 1px solid black;
                      border-collapse: collapse;">'.$row->cordinators_mobileno.'</td>
                    </tr> 

                    <tr style="width:100%;  border: 1px solid black;
                   border-collapse: collapse;">
                    <td style="width:30%;  border: 1px solid black;
                 border-collapse: collapse;" >Reward Name </td>
                    <td style="border: 1px solid black;
               border-collapse: collapse;">'.$row->reward_name.'</td>
                    </tr> 

                    <tr style="width:100%;  border: 1px solid black;
                    border-collapse: collapse;">
                    <td style="width:30%;  border: 1px solid black;
                    border-collapse: collapse;" >Reward Point </td>
                    <td  style=" border: 1px solid black;
                    border-collapse: collapse;">'.$row->r_point.'</td> 
                     </tr>

                  <tr style="width:100%;  border: 1px solid black;
                    border-collapse: collapse;">
                    <td style="width:30%;  border: 1px solid black;
                    border-collapse: collapse;" >Estimate Time </td>
                    <td  style=" border: 1px solid black;
                    border-collapse: collapse;">'.$row->estimate_time.'</td> 
                     </tr>
   ';

  }
  $output .= '

  ';
  $output .= '</table>';


$filename = "Smart_Citizen";

// include autoloader
require_once APPPATH.'dompdf/autoload.inc.php';


// reference the Dompdf namespace
use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new Dompdf();

$dompdf->loadHtml($output);

// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to Browser
$dompdf->stream($filename);

$file_to_save = APPPATH. "dompdf/";
file_put_contents($file_to_save, $dompdf->output());






the file save in folder dompdf particlar

0 个答案:

没有答案