diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3da20f2..1548392 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f60de8..ba33564 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/composer.json b/composer.json index e619387..f30bfd7 100755 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/Merge.php b/src/Merge.php index 7313394..de46fc7 100644 --- a/src/Merge.php +++ b/src/Merge.php @@ -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. * @@ -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. * @@ -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); + } } } diff --git a/tests/MergeTest.php b/tests/MergeTest.php index c2f5501..57aef21 100644 --- a/tests/MergeTest.php +++ b/tests/MergeTest.php @@ -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', @@ -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); + } } diff --git a/tests/files/watermark.png b/tests/files/watermark.png new file mode 100644 index 0000000..d976199 Binary files /dev/null and b/tests/files/watermark.png differ