2017-10-15 100 views
1

進出口使用dompf試圖產生PDF並將其保存到存儲文件夾和數據庫,問題是當我嘗試生成PDF,它永遠不會加載,當我使用github它的工作示例代碼,它顯示「測試」,但是當我嘗試加載視圖它需要永遠。這是代碼我使用Dompf負載永遠laravel 4.2

$pdf = PDF::loadView('emails.myView',$myData); 
return $pdf->stream(); 

我已經使用downloadsave方法試過了,但好好嘗試一下工作和頁面加載永遠,但永遠不會生成PDF文件。

並且該視圖僅顯示4個或6個元素,其中1個主調用$hist,返回該視圖時沒有任何問題。

<style type="text/css"> 
     Bunch of css. 
</style> 

<table class="center-block"> 
    <tr> 
     <td colspan="3"> 
      <img src="{{ asset('images/boletin/btn_cabeza.jpg') }}" class="img-responsive center-block"> 
     </td> 
    </tr> 
    <tr> 
     <td rowspan="4" class="aside"> 
      <a href="{{ URL::to('contacto/donaciones') }}"> 
       <img src="{{ asset('images/boletin/btn_dona.jpg') }}" class="img-responsive center-block" > 
      </a> 

      <div class="social-container"> 
       <h3>Siguenos en:</h3> 
       <hr> 
       <ul> 
        <li><a href="https://twitter.com/fundaepekeina"><i class="fa fa-twitter"></i></a></li> 
        <li><a href="http://fundaepekeina.org"><i class="fa fa-instagram"></i></a></li> 
        <li><a href="https://www.facebook.com/funda.epekeina"><i class="fa fa-facebook"></i></a></li> 
        <li><a href="https://www.youtube.com/user/fundaepekeina"><i class="fa fa-youtube-play"></i></a></li> 
       </ul> 
      </div> 
      <h2 class="text-blue">Historias Epékeinas</h2> 
      <br> 
      @if(count($hist->imagenes) > 0) 
       <img src="{{ asset('images/news/'.$hist->imagenes->first()->image) }}" class="img-responsive img-boletin" alt="{{ $hist->titles->first()->text }}"> 
      @endif 
      <div class="bg-green padding-20"> 
       <h2 class="boletin-title"> 
        {{ $hist->titles->first()->text }} 
        @if(!is_null($hist->subtitle)) 
        {{ $hist->subtitle->titles->first()->text }} 
        @endif 
       </h2> 
      </div> 
      <hr> 
      <div class="text-justify"> 
       {{ substr(strip_tags($hist->descriptions->first()->text), 0, 1600) }}[...] 
       <br> 
       <a href="{{ URL::to('quienes-somos/historias-epekeinas/'.$hist->slugs->first()->text) }}" class="pull-right">Leer más</a> 
      </div> 
     </td> 
    </tr> 
    <?php $k = 0;?> 
    @foreach($article as $a) 
     @if($k == 0 || $k%2 == 0) 
      <tr> 
     @endif 
     @if(!empty($principal)) 
      @if($a->slugs->first()->text != $principal->id) 
       <td class="news fixedHeight bg-{{ $colors[$j] }}"> 

        @if(count($a->imagenes) > 0) 
         <img src="{{ asset('images/news/'.$a->imagenes->first()->image) }}" class="img-responsive center-block img-boletin" alt="{{ $a->titles->first()->text }}"> 
        @else 
         <img src="{{ asset('images/logo.png') }}" class="img-responsive center-block img-boletin" alt="{{ $a->titles->first()->text }}"> 
        @endif 
        <h2 class="boletin-title">{{ $a->titles->first()->text }}</h2> 
        <p class="text-justify">{{ substr(strip_tags($a->descriptions->first()->text), 0, 300) }} [...]</p> 
        <a target="_blank" href="{{ URL::to('noticias/'.$a->slugs->first()->text) }}" class="btn btn-default btn-xs pull-right">Leer más</a> 
        <div class="clearfix"></div> 
       </td> 
       <?php $k++; ?> 
      @endif 
     @else 
      <td class="news fixedHeight bg-{{ $colors[$j] }}"> 
       @if(count($a->imagenes) > 0) 
        <img src="{{ asset('images/news/'.$a->imagenes->first()->image) }}" class="img-responsive center-block img-boletin" alt="{{ $a->titles->first()->text }}"> 
       @else 
        <img src="{{ asset('images/logo.png') }}" class="img-responsive center-block img-boletin" alt="{{ $a->titles->first()->text }}"> 
       @endif 
       <h2 class="boletin-title">{{ $a->titles->first()->text }}</h2> 
       <p class="text-justify">{{ substr(strip_tags($a->descriptions->first()->text), 0, 300) }} [...]</p> 
       <a target="_blank" href="{{ URL::to('noticias/'.$a->slugs->first()->text) }}" class="btn btn-default btn-xs pull-right">Leer más</a> 
       <div class="clearfix"></div> 
      </td> 
      <?php $k++; ?> 
     @endif 
     <?php $j++; ?> 
      @if($j == 4) 
      <?php $j=0; ?> 
      @endif 

     @if(($k != 0 && $k%2 == 0) || $k == count($article)) 
      </tr> 
     @endif 
    @endforeach 
    <tr> 
     <td colspan="3" class="text-center"> 
      <h3>&copy; Derechos Reservados Funda Epékeina 2016.</h3> 
     </td> 
    </tr> 
</table> 
<div class="container center-block"> 
     <div class="bg-square bg-blue"></div> 
     <div class="bg-square bg-yellow"></div> 
     <div class="bg-square bg-green"></div> 
     <div class="bg-square bg-pink"></div> 
</div> 
<div class="clearfix"></div> 

什麼可能是錯的?是否有任何其他選擇生成pdf。

+0

你應該設置你的調試模式上DOMPDF不起作用檢查laravel.log文件是否有錯誤。 –

回答

0

檢查,以便這些點:

  • 對於Laravel 4 *我建議你使用這個DOMPDF包裝https://github.com/barryvdh/laravel-dompdf/tree/0.4

  • 也許你的觀點是試圖呈現出的內容頁面,嘗試要添加動態分頁符,可以通過使用page-break-before樣式化元素來完成:always;或分頁後:始終。嘗試刪除該foreach並添加1或2個靜態元素將其呈現在一個頁面中

  • 通過在HTML中使用return View::make('emails.myView',$myData)->render();來檢查視圖中的錯誤。 檢查PHP和HTML sintax,如果某些HTML標記 未關好

  • 考慮使用KNP-活潑庫Laravel https://github.com/barryvdh/laravel-snappy/tree/0.1