0

I am using dompdf in laravel to create invoice. and it works fine for me until i use image in that.

Admin Controller

 public function generateInvoice(Request $request)
{
    $user = Auth::user();
    $pdf        = PDF::loadView('pdf.invoice', $user);
    return $pdf->download('invoice.pdf');
}

And in Invoice View Page that contains the invoice template...

<style>
.block{
 display: block;
}
.minifont12{
 font-size: 12px;
}
.minifont10{
 font-size: 10px;
}
.col-md-45{
 width: 45%;
 display: inline-block;
}
.col-md-30{
 width: 30%;
 display: inline-block;
}
.col-md-25{
 width: 24%;
 display: inline-block;
}
.bluecolor{
 background-color: #C5C5EC;
}
.midtop{
 margin-top: 50px;
}
</style>
<div class="header" style="position:relative; top:10; width:100%; ">
<img src="http://localhost:8000/img/minilogo.jpg">
<div style="text-align:center; margin-top:-20px;">Retail Invoice/Bill</div>
<div style="text-align:right">Invoice No. #BTR_PB_000052</div>
</div>
<div class="content">
 <div class="minifont12 block" style="margin-top:20px;">
 <strong>Sold By:</strong> SRM Smart Solutions Pvt. Ltd.<br>
  <span class="minifont10">
   Building No. 29, Third Floor, Central Market, West Punjabi Bagh, Delhi-110026
  </span>
 </div>
 <hr>
 <div class="col-md-45">
  Order Id : BT121178273<br>
  Order Date : 24-05-2016<br>
  Invoice Date : 25-05-2016<br>
  CIN No. : U72300DL2015PTC281652
 </div>
 <div class="col-md-30">
  Avinash<br>
  H.No 30-45-5/26, Chandigari colony east, rohit cottage lane, opp. krupa comlex lane, r.k.puram post, 500 056, hdy.<br>
  Hyderabad, telangana - 500056<br>
  8099473211
 </div>
 <div class="col-md-25">
  <span class="midtop bluecolor">
   *Keep this invoice for return and refund purposes
  </span>
 </div>
</div>

but When I run the code...it will show error message Maximum execution time of 60 seconds exceeded

Please tell me what is the issue behind this..

Manish Arora
  • 259
  • 1
  • 4
  • 11
  • Have you done `php artisan vendor:publish`, then gone to your `config/` directory and then edited `dompdf.php` and then set `show_warnings = true`? Should give you a bit better error reporting. Also, can you try passing the image to the pdf view as a base 64 encoded image, and then use the content of that in the PDF? Set your source `$src = public_path().'/img/minilogo.jpg';`, then create the `$image `variable to be passed to the view: `$image = 'data: '.mime_content_type($src).';base64,'.base64_encode(file_get_contents($src));` now set the `` – Ohgodwhy Aug 19 '16 at 17:44
  • If you use a different image (say from a public server) do you still have the issue? – BrianS Sep 07 '16 at 02:22

2 Answers2

1

I had the same issue when using a very large image. I solved the issue by changing the maximum execution time by adding this line before starting the pdf creation: ini_set('max_execution_time', 120);. You can also change this in your php.ini file if you like, just make sure you know what you're doing, as this setting applies to all scripts executed on your web server. You'll also have to restart your web server after making changes in the php.ini file.

Some other options so solve this are discussed here.

avi92
  • 11
  • 1
  • 3
-1

you can use this code :

<img src="{{ public_path("images/a.png") }}">

or can :

<div style="background: url({{ public_path("images/a.png"}})">text</div>
saeid abdi
  • 57
  • 5