Question

I'm trying to integrate HTML2PDF library in Laravel 4

They doesn't support composer so I downloaded the latest version of html2pdf

and put it to Laravel vendor directory and called the library from routes.php

Route::get('/', function()
{

require_once(dirname(__FILE__).'/../vendor/html2pdf/html2pdf.class.php');

$html2pdf = new HTML2PDF('P','A4','fr');
$html2pdf->WriteHTML('<p>Hello WOlrd</p>');
$html2pdf->Output('exemple.pdf');

});

but I'm keep getting this error

  Whoops
  ErrorException
  Undefined property: HTML2PDF::$_subFIRST_HEADER

Anyone have a solution about how to integrate html2pdf in laravel 4 ?

Was it helpful?

Solution

I've had to use a couple of libraries that don't have composer support. What I did was create a folder called 'libraries' in 'app/' directory in the root of you Laravel 4 project. Then I added a line of code to app/start/global.php:

<?php

ClassLoader::addDirectories(array(

        app_path().'/commands',
        app_path().'/controllers',
        app_path().'/models',
        app_path().'/database/seeds',
        app_path().'/libraries', // ADDED this line

    ));

Note: I've not done this before with HTML2PDF, so can't be 100% sure it will work. I think the directory structure of files in the app/libraries folder will have to follow the namespacing used in the library (if they use namespaces that is)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top