首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我有一个空白的pdf?

为什么我有一个空白的pdf?
EN

Stack Overflow用户
提问于 2021-10-21 19:22:28
回答 1查看 43关注 0票数 0

我正在尝试使用Laravel-7生成和pdf并显示它,但当我生成我的pdf时,它是空白的

这是我的ProductController和它的PDF方法:

代码语言:javascript
复制
public function PDFProducts(){

    $products = Product::all();

    $pdf = \PDF::loadView('pdf-products', compact('products'));
    return $pdf->stream('products.PDFProducts');
}   

这是我的路线:

代码语言:javascript
复制
Route::get('/pdfproduct', 'Backend\ProductController@PDFProducts')->name('products.PDFProducts');

这是我的pdf视图,名为pdf-products.blade.php:

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Productos</title>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="card-body">
    <table id="example1" class="table table-striped table-responsive" width="100%">
        <thead class="thead">

            

            <tr>
                <th style="display: none">Codigo</th>
                <th>ID</th>
                <th>Producto</th>
                <th>Tipo de Producto</th>
                <th>Marca</th>
                <th>Modelo</th>
                <th>Moneda de Compra</th>                                                                       
                <th class="quitarDecimales">Costo Total</th>
                <th>Moneda de Venta</th>
                <th class="quitarDecimales">Precio de Lista</th>
                <th>Margen Bruto</th>
                
                <th style="width: 12%">Accion</th>
            </tr>
        </thead>
        <tbody>
           
            @foreach($products as $product)
            @if($product->status == 1)
                <tr>
                    <td style="display: none">{{ $key+1 }}</td>
                    <td>{{ $product->id }}</td>
                    <td>{{$product->marca->brandName . " " . $product->modelo->modelName}}</td>
                    <td>{{ $product['ptype']['productType']}}</td>
                    <td>{{ $product->marca->brandName }}</td>
                    <td>{{ $product->modelo->modelName}}</td>
                    <td >{{ $product->coin }}</td>                                    
                    <td class="numero">{{ $product->costUSD }}</td>
                    <td>{{$product->sale_coin}}</td>
                    <td class="numero">{{$product->list_priceUSD}}</td>
                    <td class="numero">{{$product->marginUSD}}</td>
                    
                    @php
                    $count_product = App\Model\Purchase::where('product_id',$product->id)->count();
                    @endphp
                        
                </tr>
            @endif

                
            @endforeach
        </tbody>
        
    </table>
 </div><!-- /.card-body -->
 </body>
</html>

在我的view-products.blade.php中,我有以下按钮:

代码语言:javascript
复制
<a title="PDF" id="pdf" class="btn btn-sm btn-info btn btn-success" href="{{route('products.PDFProducts')}}" ><i class="fas fa-print" ></i></a>

这是我的PDF的样子:

这是我在检查时在开发工具控制台中得到的结果:

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body cz-shortcut-listen="true">
    <div class="container"></div>
</body>
</html>

而不是我的h1

EN

回答 1

Stack Overflow用户

发布于 2021-10-21 23:00:32

尝试编辑您的控制器以:

代码语言:javascript
复制
public function PDFProducts(){

    $products = Product::all();

    view()->share('products', $products);
    $pdf = \PDF::loadView('pdf-products', 
    compact('products'));
    return $pdf->stream('products.PDFProducts');
}   
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69667703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档