2015-03-17 1 views
1

Я использую плагин Larvel 4.2 и thujohn/pdf-l4.Laravel: Как загрузить HTML-страницу с диаграммой Морриса в формате PDF с использованием плагина thujohn/pdf-l4?

У меня возникла проблема с преобразованием HTML-страницы в PDF. Когда я конвертирую HTML-страницу, все на странице отображается, кроме диаграммы Морриса.

My Route

Route::post('performanceDetail/preview',[ 
    'as' => 'print.preview', 
    'uses' => '[email protected]']); 

Контроллер

public function postPerformanceDetails() 
{ 
    $data = [ 
     'event' => Input::get('events'), 
     'start_date' => Input::get('start_date'), 
     'to_date' => Input::get('to_date'), 
    ]; 
     $start_date = date('Y-m-d H:i:s',strtotime($data['start_date'].'00:00:00')); 
     $to_date = date('Y-m-d H:i:s',strtotime($data['to_date'].'23:59:59')); 
     $stats = Performance::where('event_type','=',$data['event']) 
     ->where('campaign_id',Session::get('campaignid')) 
     ->where('created_at', '>=',$start_date) 
     ->where('created_at','<=',$to_date) 
     ->groupBy('perf_date') 
     ->orderBy('perf_date', 'DESC') 
     ->remember(60) 
     ->get([ 
     DB::raw('Date(created_at) as perf_date'), 
     DB::raw('COUNT(id) as perf_count') 
     ]) 
     ->toJSON(); 
     //return $stats; 
     $campaign = Campaign::find(Session::get('campaignid')); 
     $list = CategoryList::find($campaign->categorylist_id); 
     $totalPerformance = TotalPerformance::find(Session::get('totalPerformance')); 
     //$this->layout->title = "Performance details"; 
     return PDF::load(View::make('performance.show') 
     ->with('stats',$stats) 
     ->with('campaign',$campaign) 
     ->with('list',$list) 
     ->with('start_date',$data['start_date']) 
     ->with('to_date',$data['to_date']) 
     ->with('totalPerformance',$totalPerformance))->show(); 
} 

Посмотреть

{{-- Form to view performance details --}} 
 
<html lang="en"> 
 
    <head> 
 
\t \t <p align="center"> 
 
\t \t \t <b> <font size="5" >Performance report</font></b> 
 
\t \t </p> 
 
\t </head> 
 
\t <body> 
 
\t \t <p align="center"> 
 
\t \t \t <font size="4" >{{{$campaign->template->title}}}</font></b> 
 
\t \t </p> 
 
\t \t <p> 
 
    \t \t \t <b>List:&nbsp;</b><font>{{$list->name}} </font> 
 
\t \t </p> 
 
\t \t <br> 
 
\t \t <p> 
 
\t \t \t <b>Total performance</b> 
 
\t \t </p> 
 
\t \t <p> 
 
\t \t \t <table> 
 
\t \t \t \t <thead> 
 
    \t \t \t \t <tr> 
 
     \t \t \t \t <th width="100">Campaign</th> 
 
     \t \t \t \t <th width="50" >Sent</th> 
 
     \t \t \t \t <th width="50" >Clicks</th> 
 
     \t \t \t \t <th width="50" >Loads</th> 
 
     \t \t \t \t <th width="50" >Opens</th> 
 
     \t \t \t \t <th width="50" >Views</th> 
 
    \t \t \t \t </tr> 
 
    \t \t \t </thead> 
 
    \t \t \t <tbody> 
 
    \t \t \t \t <tr> 
 
    \t \t \t \t \t <td align="center" width="200">{{{$campaign->template->title}}}</td> 
 
    \t \t \t \t \t <td align="center" width="50">{{$totalPerformance->totalSent }}</td> 
 
    \t \t \t \t \t <td width="50" align="center">{{$totalPerformance->clicks }}</td> 
 
    \t \t \t \t \t <td width="50" align="center">{{$totalPerformance->loads }}</td> 
 
    \t \t \t \t \t <td width="50" align="center">{{$totalPerformance->opens }}</td> 
 
    \t \t \t \t \t <td width="50" align="center">{{$totalPerformance->views }}</td> 
 
    \t \t \t \t </tr> 
 
    \t \t \t </tbody> 
 
\t \t \t </table> 
 
\t \t </p> 
 
\t \t <br> 
 
\t \t <p> 
 
\t \t \t <b>Date</b> 
 
\t \t </p> 
 
\t \t <p> 
 
\t \t \t From: &nbsp;{{$start_date}} &nbsp;&nbsp; To: &nbsp; {{$to_date}} 
 
\t \t </p> 
 
\t \t {{-- hosted assets for Morris charts --}} 
 
\t \t <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css"> 
 
\t \t {{ HTML::script('../bower_components/jquery/dist/jquery.min.js') }} 
 
\t \t {{ HTML::script('../bower_components/raphael/raphael-min.js') }} 
 
\t \t {{ HTML::script('../bower_components/morrisjs/morris.min.js') }} 
 
\t \t <input type="hidden" name="dataChart" id="dataChart" value="{{{$stats}}}"> 
 
\t \t <div id="mchart"> 
 
\t \t \t 
 
\t \t </div> 
 
\t \t <script type="text/javascript"> 
 
\t \t $(document).ready(function() 
 
\t \t { 
 
\t \t \t var events = $('#dataChart').val(); 
 
    \t \t console.log(events); 
 

 
\t \t \t var chart = Morris.Bar({ 
 
    \t \t barGap:1, 
 
    \t \t barSizeRatio:.10, 
 
    \t \t // ID of the element in which to draw the chart. 
 
    \t \t element: 'mchart', 
 
    \t \t // Set initial data (ideally you would provide an array of default data) 
 
    \t \t data: [0,0], 
 
    \t \t xkey: 'perf_date', 
 
    \t \t ykeys: ['perf_count'], 
 
    \t \t labels: ['Count'], 
 
    \t \t //barColors: ['#0B62A4','#f75b68','#4DA74D','#646464'], 
 
    \t \t hideHover: 'auto' 
 
    \t \t }); 
 
\t \t \t chart.setData(JSON.parse(events)); 
 
    \t \t 
 
\t \t \t 
 
\t \t }); 
 
\t \t </script> 
 
\t </body> 
 
</html>

Я попытался дис играть этот взгляд без преобразования, он был успешным. Но при выполнении вышеуказанного кода диаграмма Морриса не отображается в формате PDF.

Как это решить Пожалуйста, руководство.

+1

выглядит как диаграмма JS , который dompdf не обрабатывает. Вам придется пойти с другим пакетом (wkhtmltopdf или PhantomJS). – BrianS

ответ

0

Просто используйте {!! !!} вместо {{}} в файле вида ...

Также убедитесь, что ваш файл должен быть чем-то вроде «demo.blade.php» ..