0

I am trying to integrate html2pdf library in laravel 5.1. But it is showing error like as follows Class 'App\Http\Controllers\HTML2PDF' not found and my controller code is as follows

require_once(dirname(__FILE__).'/libs/html2pdf/html2pdf.class.php');
$html2pdf = new HTML2PDF('P','A4','en',true,'UTF-8',array(0, 0, 0, 0));
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->WriteHTML($html22);

my folder path is app/Http/Controllers/libs/html2pdf/html2pdf.class.php

i had given the correct path but still it is showing error like HTML2PDF not found. Please anyone let me know how to integrate html2pdf ? or should i do any changes in compose.json file ?

and even i included the line App\Http\Controllers\HTML2PDF at the top of the Controller page but no use.

please help me out .

Thanks

06011991
  • 797
  • 2
  • 13
  • 39

2 Answers2

0

I just downloaded the latest and it would seem there is no namespace.

Remove the use App\Http\Controllers\HTML2PDF and try instantiating html2pdf like $html2pdf = new \HTML2PDF('P','A4','en',true,'UTF-8',array(0, 0, 0, 0));

user1669496
  • 32,176
  • 9
  • 73
  • 65
  • `FatalErrorException in html2pdf.class.php line 0: Method Illuminate\View\View::__toString() must not throw an exception` this is error i am getting now ..Can you please help me. – 06011991 Sep 23 '15 at 13:30
  • you must be echoing something? – ajameswolf Sep 23 '15 at 13:45
  • That's another issue somewhere else in your code. You should check this out and if it doesn't answer your question, create a new question. http://stackoverflow.com/questions/26534016/laravel-error-method-illuminate-view-view-tostring-must-not-throw-an-excep – user1669496 Sep 23 '15 at 13:54
  • @user3158900 i just gone through the link which you shared then i added render() at view . now i m getting this error : `TokenMismatchException in VerifyCsrfToken.php line 53:` . for this i added in the view blade php page `` . But still it is giving the same error. please help me out – 06011991 Sep 24 '15 at 06:41
0

You can use this Package: https://packagist.org/packages/ensepar/html2pdf

add this to your composer.json

"ensepar/html2pdf": "4.0.6"

and run composer update

after that, you can use it in your controller like so

// add this to the beginning of your controller under the namespace declaration
use HTML2PDF;

// after that, you can use the class like so
$html2pdf = new HTML2PDF('P','A4','de',false,'UTF-8');
$doc = "<page><h1>Hello World</h1></page>";
$html2pdf->setDefaultFont('Arial');
$html2pdf->writeHTML($doc,false);
$html2pdf->Output(base_path().'/storage/app/helloworld.pdf','F');
Thomas Venturini
  • 3,500
  • 4
  • 34
  • 43