barryvdh / laravel-snappy

Laravel Snappy PDF
MIT License
2.59k stars 289 forks source link

Download & Stream Not Working After Adding Dynamic Variables #524

Open kinger251285 opened 6 months ago

kinger251285 commented 6 months ago

Laravel 10.10 Inertia Jetstream Vue Lavravel-Snappy 1.0 Local - profburial/wkhtmltopdf-binaries-osx": "0.12.1"

I am getting the below screenshot when trying to crate a PDF after adding in dynamic variables. This appears in a popup:

image

If i try stream rather than download i get a 500 error.

If i dd($pdf); then all the html output looks fine although file is null (not sure if this is correct).

viewPDF Method:

public function viewPDF($id)
    {

        $Application = AccountApplications::where('id', $id)->first();        

        $pdf = PDF::loadView('pdf.accountApplication', [ 'Application' => $Application]);        

        return $pdf->download($Application->company_name.'.pdf');

    }

pdf.accoutnApplication.blade.php

@extends('pdf.pdfLayout')
@section('content')
        <table>       
          <tbody>
            <tr>
              <td >COMPANY <span class="text-red">FULL</span> TRADING NAME AND ADDRESS.
                PLEASE ALSO INCLUDE…. PROPRIETOR’S FULL NAME
                AND ADDRESS.
              </td>
              <td>  Company Name: {{ $Application->company_name }}<br>
                    Proprietor Name: {{ $Application->proprietor_name }}<br>
                    Street Address: {{ $Application->street_address }}<br>
                    Address Line 2: {{ $Application->address_line_2 }}<br>
                    Town: {{ $Application->city }}<br>
                    County: {{ $Application->region }}<br>
                    Postcode: {{ $Application->postcode }}<br>

            </td>
              <td></td>
            </tr>
            <tr>
              <td>ALL COMPANY CONTACT TELEPHONE NUMBERS<br><br>

                  EMAIL ADDRESS</td>
              <td>  Phone: {{ $Application->company_phone }}<br><br>
                    Email: {{ $Application->company_email }}<br>
              </td>
              <td></td>
            </tr>
            <tr>
              <td>COMPANY REGISTRATION NUMBER</td>
              <td>{{ $Application->company_registration_no }}<br></td>
              <td></td>
            </tr>
            <tr>
              <td>SUBJECT TO ACCEPTANCE, AMOUNT OF CREDIT REQUIRED?</td>
              <td>{{ $Application->credit_required }}<br></td>
              <td></td>
            </tr>
            <tr>
              <td>REFERENCES X2</td>
              <td>  Reference 1: <br><br>
                    Name: {{ $Application->ref1_contact_name }}<br>
                    Company: {{ $Application->ref1_company_name }}<br>
                    Street: {{ $Application->ref1_street }}<br>
                    Town: {{ $Application->ref1_city }}<br>
                    County: {{ $Application->ref1_region }}<br>
                    Postcode: {{ $Application->ref1_postcode }}<br>
                    Email: {{ $Application->ref1_email }}<br>
                    Phone: {{ $Application->ref1_phone }}<br><br>
             </td>
              <td>  Reference 1: <br><br>
                    Name: {{ $Application->ref1_contact_name }}<br>
                    Company: {{ $Application->ref1_company_name }}<br>
                    Street: {{ $Application->ref1_street }}<br>
                    Town: {{ $Application->ref1_city }}<br>
                    County: {{ $Application->ref1_region }}<br>
                    Postcode: {{ $Application->ref1_postcode }}<br>
                    Email: {{ $Application->ref1_email }}<br>
                    Phone: {{ $Application->ref1_phone }}<br><br>
             </td>
            </tr>
            <tr>
              <td>BANK DETAILS FOR B.A.C.S SET UP</td>
              <td>Company<br><br>

ACC           12345678<br>
SORT         12-34-56</td>
              <td>E-MAIL CONTACT
 test@test.com<br><br>

for bacs confirmation</td>
            </tr>
          </tbody>
        </table>        
@endsection
kinger251285 commented 6 months ago

Further to this if i do:

$pdf = PDF::loadView('pdf.accountApplication', ['Application' => $Application])->save($Application->company_name.'.pdf');

It saves the file to the public drive and has created the pdf perfectly.