在laravel snappy pdf

时间:2019-07-25 09:52:49

标签: laravel laravel-5 laravel-snappy

我正在尝试创建一个pdf文件,该文件在所有页面上的价格均应位于所有价格的右侧。我这样做的方法是,每种产品都属于各自的类别,并且采用表格格式。现在,由于每个类别具有不同数量的产品,因此并非所有类别最终都在新页面上开始。我也在用barryvdh / snappy

这是我的产品-pdf.blade.php

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>

<body style="font-family: arial;">
  <div style="text-align: center; font-size: 40px;">Product Catalogue</div>

  <div>
    @foreach($product_categories as $category)
      @if(count($category->parentCategory()->where('category_id', '>', 0)->where('active', '1')->get()) && $category->active == 1)
        <div style="text-align: center; font-size: 40px; padding-top: 20px;">
          {{ $category->title }} !!
        </div>

        <table width="100%">
          <tr>
            <td colspan="2"></td>
            <td>Price</td>
          </tr>
        </table>

        @if(count($category->parentCategory))
          @foreach($category->parentCategory as $parent)
            @if(count($parent->parentCategory()->where('category_id', '>', 0)->where('active', 1)->get()) && $parent->active == 1)
              <div style="text-align: center; font-size: 40px; padding-top: 20px;">
                {{ $parent->title }} @@
              </div>

              @if(count($parent->parentCategory))
                @foreach($parent->parentCategory as $child)
                  @if($child->active == 1)
                    <div style="text-align: center; font-size: 40px; padding-top: 20px;">
                      {{ $child->title }} ##
                    </div>


                    <table width="100%">
                      @foreach($child->product as $product)
                        <tr class="page">
                          <td style="border-bottom: 2px solid #bab6b6;">
                            <?php
                              $image = getImagesArray($product->image);
                            ?>

                            @if(!empty($image))
                              <img src={!! asset("product_images/products/$image[0]") !!} width="100">
                            @endif
                          </td>

                          <td style="border-bottom: 2px solid #bab6b6;">
                            <div>
                              {{ $product->supplier_code }}
                            </div>

                            <div>
                              {{ $product->description }}
                            </div>
                          </td>

                          <td style="border-bottom: 2px solid #bab6b6; text-align: right;">
                            R {{ $product->unit_price }}
                          </td>
                        </tr>
                      @endforeach
                    </table>
                  @endif
                @endforeach
              @endif
            @elseif($parent->active == 1)
              <div style="text-align: center; font-size: 40px; padding-top: 20px;">
                {{ $parent->title }} $$

                <table width="100%">
                  @foreach($parent->product as $product)
                    <tr>
                      <td style="border-bottom: 2px solid #bab6b6;">
                        <?php
                          $image = getImagesArray($product->image);
                        ?>

                        @if(!empty($image))
                          <img src={!! asset("product_images/products/$image[0]") !!} width="100">
                        @endif
                      </td>

                      <td style="border-bottom: 2px solid #bab6b6;">
                        <div>
                          {{ $product->supplier_code }}
                        </div>

                        <div>
                          {{ $product->description }}
                        </div>
                      </td>

                      <td style="border-bottom: 2px solid #bab6b6; text-align: right;">
                        R {{ $product->unit_price }}
                      </td>
                    </tr>
                  @endforeach
                </table>
              </div>
            @endif  
          @endforeach
        @endif
      @elseif($category->active == 1 && $category->category_id == 0)
        <div style="text-align: center; font-size: 40px; padding-top: 20px;">
          {{ $category->title }} %%
        </div>

        <table width="100%">
          @foreach($category->product as $product)
            <tr>
              <td style="border-bottom: 2px solid #bab6b6;">
                <?php
                  $image = getImagesArray($product->image);
                ?>

                @if(!empty($image))
                  <img src={!! asset("product_images/products/$image[0]") !!} width="100">
                @endif
              </td>

              <td style="border-bottom: 2px solid #bab6b6;">
                <div>
                  {{ $product->supplier_code }}
                </div>

                <div>
                  {{ $product->description }}
                </div>
              </td>

              <td style="border-bottom: 2px solid #bab6b6;">
                R {{ $product->unit_price }}
              </td>
            </tr>
          @endforeach
        </table>
      @endif
    @endforeach
  </div>
</body>

这是我的downloadPdf函数

public function downloadPdf()
{
  $products = Product::all();

  $categories = Category::with('product')->where('active', 1)->where('category_id', '>', '1')->get();

  $product_categories = Category::where('category_id', 0)->with('parentCategory')->get();

  $pdf = PDF::loadView('admin.pdf.product-pdf', compact('categories', 'product_categories'));

  return $pdf->download('catalogue.pdf');
}

我确实尝试过这个

$pdf->setOption('header-html', 'http://laravel-pdf.test/admin/pdf/header');
  

退出状态代码“ 1”表示出了点问题:stderr:“正在加载页面(1/6)[>] 0%[======>] 10%[======== = 50%[=========================== ================>] 65%错误:无法加载http://laravel-pdf.test/admin/pdf/header,网络状态码为299,http状态码为500-下载http://laravel-pdf.test/admin/pdf/header时出错-服务器回复:内部服务器错误[=========================================== =================] 100%[======>] 10%[================== ============> = 50%[=============================== ===========================] 100%计数页面(2/6)[============= ==============================================]对象1 of 1解析链接(4/6)[======================================= =====================]对象1/1加载页眉和页脚(5/6)打印页面(6/6)[>]准备完成并退出代码1由于网络错误:UnknownContentError“ stdout:”“命令:” C:\ Program Files \ wkhtmltopdf \ bin \ wkhtmltopdf“ --lowquality --header-html” http://laravel-pdf.test/admin/pdf/header“” C:\ WINDOWS \ TEMP \ knp_snappy5d397 9ce2845b7.57696581.html“” C:\ WINDOWS

0 个答案:

没有答案