簡體   English   中英

如何使用Codeigniter生成pdf?

[英]How to generate pdf using Codeigniter?

我嘗試使用dompdf。 以下是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");
}

report.php中的數據

 $(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> 

生成pdf報告,但僅存在html數據。 缺少ajax和jquery數據。 沒有生成圖並且表沒有數據。我應該怎么做才能生成完整的報表,其中包含完整表中的圖和ajax數據。 在這里,視圖按原樣獲取,但是從ajax獲取的數據全部丟失。

編輯:請提出一些可能適合實現此目標的建議。

試試這個

//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);

希望這可以工作。 謝謝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM