Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kavyajain's avatar

PDF Generator using barryvdh/laravel-snappy

How to generate a pdf using data. I am using windows.

$pdfData = ['title' => 'Booking Confirmation Receipt', 'patientInfo' => $patientInfo, 'bookingDetails' => $result_book, 'rooms' => $roomCategory];
$file_path  = public_path().'\uploads\Bills\';
$snappy = new Pdf(base_path('vendor\h4cc\wkhtmltopdf-amd64\bin\wkhtmltopdf-amd64'));
$snappy->generateFromHtml('bookingConfirmReceipt', $pdfData);

I have defined patientInfo, roomcategory etc above the code.

bookingConfirmReceipt.blade .php

<!DOCTYPE html>
<html>
<body>
    <div class="container">
        <div style="border : 1px solid #efefef;padding: 20px;font-size: 14px;">
            <p>Dear<br><br>
            Your In-Patient confirmation is done, with Sadaka's ID - SHTVN_18. Kindly note, you are <span style="font-weight: bold;">not required</span> to contact the Hospital to reconfirm the same. We hope you have a pleasant stay.<br><hr style="border: 0.5px solid #000;">
            You will need to carry a printout of this and original ID card and present it at the reception at the time of admission.
            </p>
        </div>
        <h3 class="text-center" style="padding: 30px 0 5px 0;font-size: 18px;">Sadaka's Details</h3>
        /*<table class="table table-bordered sadaka-table" style="max-width: 90%;margin-left: 30px;">
          <tr>
                <th>Name</th>
                @foreach($patientInfo as $key => $value)
                <th>{{$value->masters->fullName}}</th>
                @endforeach
            </tr>
            <tr>
                <th>Phone No</th>
                @foreach($patientInfo as $key => $value)
                <th>{{$value->masters->phonenumber}}</th>
                @endforeach
            </tr>
        </table>
        <table class="table reservation-table" style="margin: 35px 0;">
            <tbody style="max-width: 90%;border : 1px solid #a3a3a3;">
                <tr>
                    <th class="text-center">Reservation Details</th>
                    <th class="text-center">Received</th>
                </tr>
                <tr>
                    <td>Check In : {{$bookingDetails->checkIn}}
                        <br>
                        Check Out : {{$bookingDetails->checkOut}}
                        <br>
                        No. of Person : {{count($patientInfo)}} 
                        <br>
                        Room Type : {{$rooms->room_category}}
                        <br>
                        No. of Room : {{$bookingDetails->totalRooms}}
                    </td>
                    <td>Advance Amount : {{$bookingDetails->advanceAmount}}</td>
                </tr>
            </tbody>
        </table>*/
        <p style="margin-bottom: 0px;">Note :</p>
        <ol style="font-size: 15px;line-height: 26px;">
            <li>This is not a bill for the In-patient room charges. It will be issued in the hospital at the time of discharge.</li>
            <li>the amount collected is a security deposit against cancellation and is liable to be forfeited partly or fully, if the booking is cancelled.</li>
            <li>If the Sadhaka does not avail the room on the booked date, the deposit will be fully forfeited.</li>
            <li>This is computer generated document and hence does not require a signature.</li>
        </ol>
    </div>
</body>
</html>

It is generating empty pdf. Please Help

0 likes
2 replies
Kavyajain's avatar
use Barryvdh\Snappy\Facades\SnappyPdf as PDF;
.
.
.
$pdf = PDF::loadView('bookingConfirmReceipt', $pdfData)->save(public_path().'\uploads\Bills\'.$fileName.'.pdf');
        return $pdf->download('invoice.pdf');

This is also generating empty pdf

Please or to participate in this conversation.