Home » Php » php – Laravel HTML to PDF conversion (DOMPDF)

php – Laravel HTML to PDF conversion (DOMPDF)

Posted by: admin July 12, 2020 Leave a comment


DOMPDF Wrapper for Laravel 5, It’s a html to pdf converter for laravel 5.

I have tried to convert laravel default auth register page to PDF and the path is http://www.careertag.dev/auth/register. Code used for this purpose is given below. But I am getting font issue. Could you please help me to solve this issue?


Route::post('/screenshot', function(){
    $pdf  =  App::make('dompdf.wrapper');
    $view =  View::make('auth.register')->render();
    //return $pdf->stream('invoice');
    return $pdf->download('profile.pdf');


ErrorException in font_metrics.cls.php line 343: file_put_contents(C:\xampp\htdocs\careertag\storage\fonts/13350985545a9988387f8a573f409063.ttf): failed to open stream: No such file or directory
How to&Answers:

Create fonts folder inside storage directory and make sure storage is writable by web server by running follwing command. This worked for me.

sudo chmod -R 777 storage

Above (777) can be dangerous, therefore to achieve it in a secure way, try the below commands.

sudo find storage -type d -exec chmod 755 {} \; 
sudo find storage -type f -exec chmod 644 {} \;


Copy the ‘fonts’ directory of your theme form the location ‘project-directory/public/themes/your-theme/path-to-fonts-directory’ to the location
This works for me when I was hanged for long time.