Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel HTML to PDF conversion (DOMPDF)

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?

routes.php

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

Error

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
like image 691
Sarath TS Avatar asked Sep 22 '15 09:09

Sarath TS


People also ask

How do I convert HTML to PDF in Laravel?

The Dompdf library can be used to convert HTML to PDF using PHP. The Dompdf is a PHP library that helps to convert HTML to PDF document. If your application is built with Laravel, the Dompdf library is the best option to create a PDF file and add HTML content to PDF document.

What is Dompdf in Laravel?

Dompdf is a query based on the Laravel framework that will help generate a pdf file. It can be integrated in any environment, based on a Laravel framework. Laravel, as we all know is one of the most popular of frameworks and over the years has become the most sought after for e commerce solutions.


2 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 {} \;
like image 160
Mustafa Ehsan Alokozay Avatar answered Sep 24 '22 05:09

Mustafa Ehsan Alokozay


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

like image 42
Md Aman Ullah Avatar answered Sep 23 '22 05:09

Md Aman Ullah