2017-12-30 10 views
0

나는 dompdf를 사용해 보았습니다. 다음은 report.phpCodeigniter를 사용하여 pdf를 생성하는 방법은 무엇입니까?


 
    $(document).ready(function(){ 
 
     
 
    
 
    
 
    
 
$.ajax({ 
 
       type: "POST", 
 
       url: $u+"get", 
 
       data: { 
 
        
 
        role:"report", 
 
        }, 
 

 
       datatype: "json", 
 
       crossDomain: true, 
 
       success: function(result) { 
 
        var result = $.parseJSON(result); 
 
        for (var result in syncx) { 
 

 
        $("#tta tbody").append("<tr ><td class='cyan'>"+x+"</td><td>"+syncx[x].total+ "</td> </tr>"); 
 
          
 
         } 
 
        
 
         Morris.Line({ 
 
       element: 'total-line', 
 
       data: source, 
 
       behaveLikeLine: true, 
 
       parseTime : false, 
 
       xkey: 'x', 
 
       ykeys: [ 'totol'], 
 
       labels: [ 'total'], 
 
       pointFillColors: ['#707f9b'], 
 
       pointStrokeColors: ['#ffaaab'], 
 
       lineColors: ['#f26c4f', '#00a651', '#00bff3'], 
 
       redraw: true 
 
      }); 
 

 
       } 
 
} 
 
          }); 
 

 
    
 
}); 
 

 
    
 

 
    
 
    
 
    
 
<body> 
 
    <div class="row "> 
 
     
 
     
 
      <div id="responsive" class=" "> 
 
     <h4 > Record</h4> 
 
     <div class=" "> 
 
      <div id="flip-scroll" class="card"> 
 
      <p> </p> 
 
      <table id="tta" > 
 
       <thead> 
 
       <tr> 
 
        <th>x</th> 
 
        <th>Total </th> 
 
        
 
       </tr> 
 
       </thead> 
 
       <tbody> </tbody> 
 
      </table> 
 
      </div> 
 
     </div> 
 

 
     </div> 
 

 
     
 
     </div> 
 

 
     
 
    
 
    <div class="col "> 
 
     <div class="card"> 
 
     <div class="card-image"> 
 
      <div id="total-line"></div> 
 
      <span class="card-title"> </span> 
 
      
 
     </div> 
 
     <div class="card-content"> <p>Total</p> 
 
    </div> 
 
     </div> 
 
    </div> 
 
    
 
    
 
    
 

 
</body> 
 

에 CodeIgniter의

function get_pdf() 
{ 
$this->load->library('Pdf'); 
$this->pdf->load_view('report.php'); 
$this->pdf->load_html('report.php','',true); 
$this->pdf->render(); 
$this->pdf->stream("welcome.pdf"); 
} 

데이터에 컨트롤러 인 PDF 보고서가 생성되지만 HTML 데이터가 있었다한다. 아약스 및 jquery 데이터가 누락되었습니다. 그래프가 생성되지 않고 테이블에 데이터가 없습니다. 여기에 그래프와 아약스 데이터가 포함 된 전체 보고서를 생성하려면 어떻게해야합니까? 여기서 뷰는 그대로 가져 오지만 아약스에서 가져온 데이터는 모두 누락됩니다.

편집 :이 작업을 수행하는 데 적합한 다른 것을 제안하십시오.

답변

0

이가 일할 수있는이 일

//File name 
$filename = "Whatever-you-wish"; 

//Data can be any variables that you want to pass it on to the view.If you don't have anything to pass, just add null to the 2nd parameter. 
$html = $this->load->view('sample',$data, true); 

//load library. I assume you have already uploaded the dom files under application/library folder 
$this->load->library('pdf'); 

//Intitialize dompdf object 
$dompdf = new Dompdf\Dompdf(); 

//add view 
$dompdf->load_html($html); 

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

//If you have any options to add it to this function 
$options = new Dompdf\Options(); 
$options->set('isRemoteEnabled', TRUE); 

//Default paper size 
$dompdf->set_paper('DEFAULT_PDF_PAPER_SIZE', 'portrait'); 

//Output the result 
$output = $dompdf->output(); 

//Save it to the folder. Folder has to be created outside the application folder. 
file_put_contents('your-folder-name/' . $filename . '.pdf', $output); 

희망을 봅니다. 고맙습니다.

관련 문제