0
votes

I am trying convert blade view to pdf. If i use normal text i am able to generate the pdf. I have few images in my blade template and with that i am not able to generate pdf.

Here is my blade template code.

<html>
<head>
  <link href="{{ asset('css/bootstrap.min.css') }}" rel="stylesheet">
</head>
<body>
  <div class="container">
    <div class="row col-md-12">
      <div class="col-md-5">
        <table>
          <tr>
            <td>ID</td>
            <td>:</td>
            <td>CO12345</td>
          </tr>
          <tr>
            <td>Date</td>
            <td>:</td>
            <td>CO12345</td>
          </tr>
          <tr>
            <td>Contract/PO #</td>
            <td>:</td>
            <td>C122</td>
          </tr>
          <tr>
            <td>Job ID</td>
            <td>:</td>
            <td>0001</td>
          </tr>
          <tr>
            <td>Client Name</td>
            <td>:</td>
            <td>Hong</td>
          </tr>
          <tr>
            <td>Project</td>
            <td>:</td>
            <td>Lake Nona Place</td>
          </tr>
          <tr>
            <td>Address</td>
            <td>:</td>
            <td>123 Roy street, Suit 107, Lake Nona, FL 32817</td>
          </tr>
        </table>
      </div>
      <div class="col-md-7">
        <img src="images/logo.jpg " class="float-right img-responsive img-thumbnail">
      </div>
    </div>
    <div class="my-auto mx-auto text-center">
      <h4>Change Order</h4>
    </div>
    <div class="row col-md-12">
      <table class="table table-bordered">
        <thead>
          <tr>
            <td><b><p class="text-md-center">Line</p></b></td>
            <td><b><p class="text-md-center">Title</p></b></td>
            <td><b><p class="text-md-center">Description</p></b></td>
            <td><b><p class="text-md-center">Total</p></b></td>
          </tr>
        </thead>
        <body>
          <tr>
            <td><p class="text-md-center">1</p></td>
            <td><p class="text-md-center">B12, Unit 114</p></td>
            <td><p class="text-md-center">Replace damage carpate in master bedroom.</p></td>
            <td><p class="text-md-center">$250</p></td>
          </tr>
          <tr>
            <td colspan="3"></td>
            <td><p class="text-md-center">$250</p></td>
          </tr>
        </body>
      </table>
    </div>
    <hr/>
    <div class="col-md-12 row">
      <div class="col-md-3">
        <img src="images/logo.jpg " class="float-right img-responsive img-thumbnail">
      </div>
      <div class="col-md-3">
        <img src="images/logo.jpg " class="float-right img-responsive img-thumbnail">
      </div>
      <div class="col-md-3">
        <img src="images/logo.jpg " class="float-right img-responsive img-thumbnail">
      </div>
      <div class="col-md-3">
        <img src="images/logo.jpg " class="float-right img-responsive img-thumbnail">
      </div>
    </div>
    <hr/>
    <div class="my-auto">
      <p>
        I hereby authorize <b>John</b> to perform the extra work listed above. I further state that I am authorized to
        approve this extra work and that my signature below serves as a payment commitment of such.
       </p>
    </div>
  </div>

   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
   <script src="{{ asset('js/bootstrap.min.js') }}"></script>
</body>
<html>

Here is code snippet from controller class which generates pdf.

public function generatePdf(){
  $pdf = PDF::loadView('template1');
  return $pdf->download('template1.pdf');
}

I am using this https://github.com/barryvdh/laravel-dompdf for pdf.

enter image description here

2
What kind of error that you got? Can you please add the complete error message on your question?Dharma Saputra
@DharmaSaputra, question updated with error.Hitendra

2 Answers

0
votes

You may increase php max_execution_time. But it's not recommended because It may crashing your server if there are many user generate the PDF at the same time. Things you need to try:

  1. Make sure the image size is small, you don't need very high quality image for the pdf, right?
  2. Remove javascripts loading, it's useless anyway.
  3. Separate css file just for the pdf. So there are only style needed by the pdf being loaded.

Additional information from laravel-dompdf github: https://github.com/barryvdh/laravel-dompdf/issues/184

Hope it helps

0
votes

use public_path() instead of asset().