Skip to content

Commit 3c5b5df

Browse files
committed
Update documentation
1 parent 480ecdb commit 3c5b5df

File tree

4 files changed

+151
-1
lines changed

4 files changed

+151
-1
lines changed

README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,102 @@
1+
2+
<p align="center"><img src="https://static.typeset.sh/images/typeset.sh-logo.svg" width="300"></p>
3+
4+
15
# Typeset.sh wrapper for laravel 7
26

7+
This is a laravel 7 typeset.sh wrapper that lets you easily configure and use typeset.sh
8+
in your laravel project.
9+
10+
11+
## Installation
12+
13+
Make sure you have access to a valid composer token from typeset.sh.
14+
15+
Add typeset.sh packages repository to composer.
16+
17+
composer config repositories.typesetsh composer https://packages.typeset.sh
18+
composer require typesetsh/laravel-wrapper
19+
20+
21+
Then add the following line to register provider in `config/app.php`
22+
```php
23+
'providers' => [
24+
25+
// ...
26+
27+
App\Providers\AppServiceProvider::class,
28+
App\Providers\AuthServiceProvider::class,
29+
App\Providers\EventServiceProvider::class,
30+
App\Providers\RouteServiceProvider::class,
31+
[+] Typesetsh\LaravelWrapper\ServiceProvider::class,
32+
33+
],
34+
```
35+
36+
37+
## Usage
38+
39+
The wrapper works similar to the view. Technically it wraps the view and uses its html output
40+
and renders it as pdf.
41+
42+
### Facade
43+
44+
You can use the facade pattern. Similar as you would render a view.
45+
46+
```php
47+
use Typesetsh\LaravelWrapper\Facades\Pdf;
48+
49+
Route::get('/invoice/print', function () {
50+
$invoice = new stdClass();
51+
52+
return Pdf::make('invoice', ['invoice' => $invoice]);
53+
});
54+
```
55+
56+
57+
### Helper
58+
59+
Alternative you can use the helper.
60+
61+
```php
62+
use Typesetsh\LaravelWrapper\Facades\Pdf;
63+
64+
Route::get('/invoice/print', function () {
65+
$invoice = new stdClass();
66+
67+
return typesetsh\pdf('invoice', ['invoice' => $invoice]);
68+
});
69+
```
70+
71+
or force a download
72+
73+
```php
74+
use Typesetsh\LaravelWrapper\Facades\Pdf;
75+
76+
Route::get('/invoice/print', function () {
77+
$invoice = new stdClass();
78+
79+
return typesetsh\pdf('invoice', ['invoice' => $invoice])->forceDownload('invoice.pdf');
80+
});
81+
```
82+
83+
84+
## Configuration
85+
86+
Typeset.sh does not require much configuration. The only important aspect to understand is that
87+
by default typeset.sh does not allow including any external resources (image, css, fonts,...)
88+
unless specified.
89+
90+
See the configuration file `config/typesetsh.php` for more information. By default, typeset.sh
91+
has access to the public directory and any http(s) resources.
92+
93+
You can also publish the file using:
94+
95+
php artisan vendor:publish --provider="Typesetsh\LaravelWrapper\ServiceProvider"
96+
97+
98+
## License
99+
100+
This extension is under the [MIT license](LICENSE).
101+
102+
However, it requires a version of [typeset.sh](https://typeset.sh/) to work.

config/typesetsh.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,52 @@
11
<?php
22

33
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Allowed directories
7+
|--------------------------------------------------------------------------
8+
|
9+
| You must list all directories that typeset.sh can use to load
10+
| resources such as images, css or font files.
11+
| By default only the public directory is allowed.
12+
|
13+
*/
14+
415
'allowed_directories' => [public_path()],
516

17+
/*
18+
|--------------------------------------------------------------------------
19+
| Allowed protocols for downloading
20+
|--------------------------------------------------------------------------
21+
|
22+
| You can prevent downloading any resource from the web or add additional
23+
| protocols if they are supported by curl.
24+
|
25+
*/
26+
627
'allowed_protocols' => ['http', 'https'],
728

29+
/*
30+
|--------------------------------------------------------------------------
31+
| Cache directory
32+
|--------------------------------------------------------------------------
33+
|
34+
| Used when downloading resources (images, css, fonts,...) from a remote
35+
| location.
36+
|
37+
*/
38+
839
'cache_dir' => storage_path('framework/cache/typesetsh'),
940

41+
/*
42+
|--------------------------------------------------------------------------
43+
| Timeout
44+
|--------------------------------------------------------------------------
45+
|
46+
| Max timeout when downloading remote resources. Only works when ext-curl
47+
| is available.
48+
|
49+
*/
50+
1051
'timeout' => 15,
1152
];

src/Pdf/View.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ public function __construct(HtmlView $view, Typesetsh $pdf)
3737
$this->pdf = $pdf;
3838
}
3939

40-
public function forceDownload(string $filename): void
40+
public function forceDownload(string $filename): self
4141
{
4242
$this->filename = $filename;
43+
44+
return $this;
4345
}
4446

4547
public function render(): string

src/ServiceProvider.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ public function register()
2626
$this->registerPdfRenderer();
2727
}
2828

29+
public function boot()
30+
{
31+
$this->publishes([
32+
self::CONFIG_PATH => base_path('config/typesetsh.php'),
33+
]);
34+
}
35+
2936
protected function registerPdfRenderer(): void
3037
{
3138
$this->app->singleton('typesetsh', function ($app) {

0 commit comments

Comments
 (0)