thujohn / pdf-l4

Dompdf for Laravel 4
MIT License
228 stars 72 forks source link

how to include stylesheet in blade template? #24

Open isimmons opened 10 years ago

isimmons commented 10 years ago

I had this working with plain dompdf but had to set the base path

$dompdf->set_base_path(public_path().'/css/pdf/);

and it wouldn't work with {{ HTML::style('style.css') }}

I had to manually put in a link tag

<link rel="stylesheet" type="text/css" href="style.css">

With this package I get the same issue when using {{ HTML::style('style.css') }} which is a long wait and then a timeout.

Trying to use the manual link and the pdf is generated but with no styles. Since I didn't see a way to set_base_path() I assume this is set to public_path() by default since it's for Laravel but my stylesheet still isn't working

isimmons commented 10 years ago

For a quick fix I added to the published config file

'DOMPDF_SET_BASE_PATH' => public_path().'/css/pdf/'

Then in the constructor of Thujohn/Pdf/Pdf.php

$this->dompdf = new \DOMPDF();
...
$basePath = Config::get('pdf::config.DOMPDF_SET_BASE_PATH');
$this->dompdf->set_base_path($basePath);

Any chance of getting this config setting added in the next version? Sorry if there is already a way to do this.

isimmons commented 10 years ago

I guess that would be better put in the load() function. Was wondering if it should be a config setting recognizable by people reading the dompdf wiki or would be more flexible if passed into load() as a third parameter.

thujohn commented 10 years ago

I just tested and I have no problem.

Here is my test : http://paste.laravel.com/18zZ

isimmons commented 10 years ago

Just tried copying your test and I get the same result. I'm on a windows 7 machine. Do you think dompdf reading paths on windows could be an issue? Maybe why the set_base_path() method and only href="style.css" is working?

I've got a vagrant linux setup so I'll give it a try there.

Thanks

thujohn commented 10 years ago

I'm on Win 7 too ;)

I just updated my lab repo so you can try with it : https://github.com/thujohn/lab Here the result : http://lab.packalyst.com/pdf/css

isimmons commented 10 years ago

Ah, this works on a real server. I was running it with php artisan serve and this is the result I get. Copied over to my www and ran it and it works fine

Laravel development server started on http://localhost:8000
[Mon Nov 18 16:35:52 2013] ::1:56551 [200]: /favicon.ico
[Mon Nov 18 16:37:59 2013] PHP Fatal error:  Maximum execution time of 60 seconds exceeded in C:\Users\lotus\laracasts\lab\vendor\thujohn\pdf\src\Thujohn\Pdf\dompdf\include\functions.inc.php on line 762
[Mon Nov 18 16:37:59 2013] ::1:56554 [200]: /assets/css/pdf-css.css
[Mon Nov 18 16:38:00 2013] ::1:56677 [200]: /favicon.ico
thujohn commented 10 years ago

I tested on my local server but I don't use artisan serve

Have you tried without ?

isimmons commented 10 years ago

Yes sorry, that's what I meant. It works with local Apache server so I can use that or use vagrant instead of artisan serve.