Skip to content

Commit

Permalink
Merge pull request #33 from jeffreyvanhees/main
Browse files Browse the repository at this point in the history
Add ->paperSize()-method
  • Loading branch information
freekmurze committed Jan 14, 2024
2 parents 66b492a + 4286eda commit 0a4d46e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/basic-usage/formatting-pdfs.md
Expand Up @@ -86,6 +86,18 @@ A5: 5.83in x 8.27in
A6: 4.13in x 5.83in
```

### Paper size

If you don't want to use standardized formats, you can also use the `paperSize` method instead.

```php
use Spatie\LaravelPdf\Facades\Pdf;

Pdf::view('pdf.receipt', ['order' => $order])
->paperSize(57, 500, 'mm')
->save('/some/directory/receipt-12345.pdf');
```

### Page margins

Margins can be set using the `margins` method. The unit of the margins is millimeters by default.
Expand Down
9 changes: 9 additions & 0 deletions src/PdfBuilder.php
Expand Up @@ -203,6 +203,15 @@ public function format(string|Format $format): self
return $this;
}

public function paperSize(float $width, float $height, string $unit = 'mm'): self
{
$this->withBrowsershot(function (Browsershot $browsershot) use ($width, $height, $unit) {
$browsershot->paperSize($width, $height, $unit);
});

return $this;
}

public function withBrowsershot(callable $callback): self
{
$this->customizeBrowsershot = $callback;
Expand Down
10 changes: 10 additions & 0 deletions tests/PdfTest.php
Expand Up @@ -106,6 +106,16 @@
->toContainText('This is a test');
});

it('can accept the page size', function () {
Pdf::view('test')
->paperSize(200, 400, 'mm')
->save($this->targetPath);

expect($this->targetPath)
->toHaveDimensions(567, 1134)
->toContainText('This is a test');
});

it('can accept the orientation', function () {
Pdf::view('test')
->orientation(Orientation::Landscape)
Expand Down

0 comments on commit 0a4d46e

Please sign in to comment.