Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Laravel 9 #8

Merged
merged 5 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.3, 7.4, 8.0]
laravel: [6.*, 7.*, 8.*]
php: [7.3, 7.4, 8.0, 8.1]
laravel: [6.*, 7.*, 8.*, 9.*]
dependency-version: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to `easy-pdf` will be documented in this file.

## [Unreleased]

## 2.3.0 - 2022-02-08
- Add support for Laravel 9.

## 2.2.0 - 2022-01-14
- `$pdf` variable changed to public variable in `EasyPdf.php`
- SVG support added to `setImage` method.
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
}
],
"require": {
"php": "^7.3 || ^8.0",
"illuminate/support": "6.11.0|^7.0|^8.0",
"php": "^7.3|^8.0|^8.1",
"illuminate/support": "6.11.0|^7.0|^8.0|^9.0",
"setasign/fpdi-tcpdf": "^2.2",
"tecnickcom/tcpdf": "^6.3",
"ext-fileinfo": "*"
},
"require-dev": {
"mockery/mockery": "^1.3",
"orchestra/testbench": "^4.0|^5.0|^6.0",
"orchestra/testbench": "^4.0|^5.0|^6.0|^7.0",
"phpunit/phpunit": "^9.0"
},
"autoload": {
Expand Down
30 changes: 30 additions & 0 deletions src/Merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ class Merge extends BasePdf
*/
protected $files;

protected $watermark;
protected $w_x;
protected $w_y;
protected $w_width;
protected $w_height;

/**
* Merge constructor.
*
Expand All @@ -23,6 +29,27 @@ public function __construct(array $files)
$this->files = $files;
}

/**
* Add watermark to each page.
*
* @param $watermark
* @param $x
* @param $y
* @param $width
* @param $height
* @return $this
*/
public function addWatermark($watermark, $x = null, $y = null, $width = 0, $height = 0)
{
$this->watermark = $watermark;
$this->w_x = $x;
$this->w_y = $y;
$this->w_width = $width;
$this->w_height = $height;

return $this;
}

/**
* Merge pdf files into one pdf.
*
Expand All @@ -41,6 +68,9 @@ public function render()
$this->pdf->AddPage();
$importedPage = $this->pdf->ImportPage($page);
$this->pdf->useTemplate($importedPage);
if ($this->watermark) {
$this->pdf->Image($this->watermark, $this->w_x, $this->w_y, $this->w_width, $this->w_height);
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions tests/MergeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@

class MergeTest extends TestCase
{
protected $file;
protected $files;

protected function setUp(): void
{
parent::setUp();

$this->file = __DIR__.'/files/file.pdf';

$this->files = [
__DIR__.'/files/file.pdf',
__DIR__.'/files/anotherFile.pdf',
Expand All @@ -31,4 +34,19 @@ public function it_can_merge_multiple_files_into_one_file()

$this->assertSame('application/pdf; charset=binary', $buffer);
}

/** @test */
public function it_can_add_watermark_into_the_file()
{
$easyPdf = new EasyPdf();
$pdf = $easyPdf->reset()
->merge([$this->file])
->addWatermark(__DIR__.'/files/watermark.png')
->content();

$finfo = new finfo(1040);
$buffer = $finfo->buffer($pdf);

$this->assertSame('application/pdf; charset=binary', $buffer);
}
}
Binary file added tests/files/watermark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.