generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b61e408
commit d9d4655
Showing
8 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
title: Creating PDFs with multiple pages | ||
weight: 2 | ||
--- | ||
|
||
This packages offers a couple of Blade directives to help you create PDFs with multiple pages. | ||
|
||
## Setting a page break | ||
|
||
To create a PDF with multiple pages, you can use the `@pageBreak` Blade directive in your view. Using this directive will result in a new page being created in the PDF document. | ||
|
||
So if you have a view like this... | ||
|
||
```blade | ||
<div> | ||
Page 1 | ||
</div> | ||
@pageBreak | ||
<div> | ||
Page 2 | ||
</div> | ||
``` | ||
|
||
... and you render this view using ... | ||
|
||
```php | ||
Pdf::view('view-with-multiple-pages')->save($path); | ||
``` | ||
|
||
... the resulting PDF will have two pages, one with "Page 1" and one with "Page 2". | ||
|
||
## Adding page numbers | ||
|
||
To add page numbers to your PDF, you can use the `@pageNumber` and `@totalPages` Blade directive in your view. | ||
|
||
Imagine you have this footer view... | ||
|
||
```blade | ||
<div> | ||
This is page @pageNumber of @totalPages | ||
</div> | ||
``` | ||
|
||
... and you render this view using ... | ||
|
||
```php | ||
Pdf::view('view-with-multiple-pages')->footer('footer-view')->save($path); | ||
``` | ||
|
||
... the resulting PDF will have a footer on each page, with the page number and the total number of pages. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
--- | ||
title: Generating PDFs on AWS Lambda | ||
weight: 2 | ||
weight: 3 | ||
--- | ||
|
||
Coming soon... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
use Spatie\LaravelPdf\Facades\Pdf; | ||
|
||
beforeEach(function () { | ||
$this->targetPath = getTempPath('test.pdf'); | ||
}); | ||
|
||
it('can set a page break', function () { | ||
Pdf::view('blade-directives.body') | ||
->save($this->targetPath); | ||
|
||
expect($this->targetPath)->toHavePageCount(2); | ||
}); | ||
|
||
it('can display the number of pages', function() { | ||
Pdf::view('blade-directives.body') | ||
->footerView('blade-directives.footer') | ||
->save($this->targetPath); | ||
|
||
expect($this->targetPath)->toContainText('page 1 of 2'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div> | ||
First page | ||
</div> | ||
@pageBreak | ||
<div> | ||
Second page | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div style="font-size: 20px"> | ||
<h1>Footer</h1> | ||
This is page @pageNumber of @totalPages | ||
</div> |