Skip to content

Commit afc8b94

Browse files
committed
Merge branch 'release/5.0.0'
2 parents 0c04058 + 8619ab7 commit afc8b94

29 files changed

+493
-579
lines changed

.github/workflows/ci.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
name: CI
22

3-
on: [pull_request]
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
- develop
49

510
jobs:
611
test:
712
runs-on: ubuntu-latest
813
strategy:
914
matrix:
10-
php-version: [ "7.4", "8.0", "8.1", "8.2", "8.3" ]
15+
php-version: [ "7.4", "8.0", "8.1", "8.2", "8.3", "8.4" ]
1116

1217
steps:
1318
- uses: actions/checkout@v4
@@ -21,6 +26,12 @@ jobs:
2126
with:
2227
php_version: ${{ matrix.php-version }}
2328

29+
- uses: php-actions/composer@v6
30+
with:
31+
php_version: ${{ matrix.php-version }}
32+
command: 'require'
33+
args: 'horstoeko/zugferd tecnickcom/tcpdf'
34+
2435
- name: Run PHPUnit tests
2536
run: vendor/bin/phpunit
2637

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](https://semver.org/).
66

7+
## [5.0.0] - 2025-01-10
8+
### Added
9+
- Merger for Zugferd PDFs, i.e. PDFs with XML attachments
10+
### Changed
11+
- TCPDF to Fpdf library for merging as default (both libraries supported now)
12+
- Several public interfaces to support type hints and make purpose clearer
13+
### Removed
14+
- Deprecated ZendPdf merger
15+
716
## [4.0.2] - 2024-10-13
817
### Changed
9-
- Updated dompdf library to 3.x
18+
- Dompdf library to version 3.x
1019

1120
## [4.0.1] - 2023-11-10
1221
### Fixed

README.md

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
# vianetz PDF Library
1+
# vianetz Pdf Library
22

33
This library offers an easy-to-use API for PDF generation and merging.
4-
Internally it uses the DomPDF library for PDF generation and TCPDF for merging.
4+
Internally it uses the [DomPDF library](https://github.com/dompdf/dompdf) for PDF generation and [FPDI](https://github.com/Setasign/FPDI) for merging.
5+
6+
More information about this PDF API can also be found [on my website](https://www.vianetz.com/en/pdf-invoice-api-magento/).
57

68
## Usage
79

8-
### Create PDF document from HTML contents
10+
### Create PDF document from HTML contents
11+
912
```php
1013
// Create a new pdf instance.
11-
$pdf = Vianetz\Pdf\Model\PdfFactory::general()->create();
14+
$pdf = \Vianetz\Pdf\Model\PdfFactory::general()->create();
1215

1316
// Create the document. You can return any kind of HTML content here.
14-
$document = new \Vianetz\Pdf\Model\Document();
15-
$document->setHtmlContents('<strong>Hello</strong> World!');
17+
$document = new \Vianetz\Pdf\Model\HtmlDocument('<strong>Hello</strong> World!');
1618

1719
// Add our document to the pdf. You can add as many documents as you like
1820
// as they will all be merged into one PDF file.
19-
$pdf->addDocument($document);
21+
$pdf->add($document);
2022

2123
// Save the resulting PDF to file test.pdf - That's it :-)
2224
$pdf->saveToFile('test.pdf');
@@ -28,15 +30,14 @@ $pdf->saveToFile('test.pdf');
2830
$pdfString = file_get_contents('test1.pdf');
2931

3032
// Setup things
31-
$pdf = Vianetz\Pdf\Model\PdfFactory::general()->create();
32-
$pdfMerge = Vianetz\Pdf\Model\PdfMerge::create();
33+
$pdfMerge = \Vianetz\Pdf\Model\PdfMerge::create();
3334

3435
// Do the merge.
35-
$pdfMerge->mergePdfString($pdfString);
36+
$pdfMerge->mergePdfString($pdfString, 'background.pdf');
3637
$pdfMerge->mergePdfFile('test2.pdf');
3738

3839
// Save the result PDF to file result.pdf.
39-
$pdfMerge->saveToFile('result.pdf');
40+
file_put_contents($fileName, $pdfMerge->toPdf());
4041
```
4142

4243
### Tips & Tricks
@@ -50,12 +51,6 @@ Please find the Frequently Asked Questions [on my website](https://www.vianetz.c
5051
If you have any issues or suggestions with this extension, please do not hesitate to
5152
[contact me](https://www.vianetz.com/en/contacts).
5253

53-
## Credits
54-
Of course this extension would not have been possible without the great open source eco-system.
55-
Therewith credits go to:
56-
- [DomPDF](https://github.com/dompdf/dompdf)
57-
- [FPDI](https://github.com/Setasign/FPDI)
58-
5954
## License
6055
[GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.html)
6156
See also LICENSE file.

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,18 @@
2727
"require": {
2828
"php": "^7.4|^8",
2929
"dompdf/dompdf": "^2.0|^3.0",
30-
"setasign/fpdi": "^2.0",
31-
"tecnickcom/tcpdf": "^6.4"
30+
"setasign/fpdi": "^2.6",
31+
"setasign/fpdf": "^1.8"
3232
},
3333
"require-dev": {
3434
"phpunit/phpunit": "^9|^10|^11",
3535
"phpstan/phpstan": "^1.8",
3636
"phpstan/phpstan-phpunit": "^1.1"
3737
},
3838
"suggest": {
39+
"horstoeko/zugferd": "Create Zugferd documents with this merger library",
3940
"vianetz/signaturportal-api": "Use this library to sign your generated PDF documents.",
40-
"zf1/zend-pdf": "Necessary if you want to use Zend_Pdf for merging. By default this package uses the fpdi merger."
41+
"tecnickcom/tcpdf": "Necessary if you want to use TCPDF for merging. By default this package uses the fpdf merger."
4142
},
4243
"config": {
4344
"allow-plugins": {

src/Exception.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
3-
* Pdf Exception Class
4-
*
55
* @section LICENSE
66
* This file is created by vianetz <[email protected]>.
77
* The code is distributed under the GPL license.

src/FileNotFoundException.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* @section LICENSE
6+
* This file is created by vianetz <[email protected]>.
7+
* The code is distributed under the GPL license.
8+
*
9+
* If you did not receive a copy of the license and are unable to
10+
* obtain it through the world-wide-web, please send an email
11+
* to [email protected] so we can send you a copy immediately.
12+
*
13+
* @package Vianetz\Pdf
14+
* @author Christoph Massmann, <[email protected]>
15+
* @link https://www.vianetz.com
16+
* @copyright Copyright (c) since 2006 vianetz - Dipl.-Ing. C. Massmann (https://www.vianetz.com)
17+
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GENERAL PUBLIC LICENSE
18+
*/
19+
20+
namespace Vianetz\Pdf;
21+
22+
class FileNotFoundException extends \Exception
23+
{
24+
}

src/Model/PdfDocumentInterface.php renamed to src/Model/CanSave.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* @section LICENSE
46
* This file is created by vianetz <[email protected]>.
@@ -17,16 +19,12 @@
1719

1820
namespace Vianetz\Pdf\Model;
1921

20-
interface PdfDocumentInterface
22+
interface CanSave
2123
{
2224
/**
23-
* @return string
24-
*/
25-
public function getPdfFile();
26-
27-
/**
28-
* @param string $pdfFile
29-
* @return void
25+
* @api
26+
* @return bool true in case of success
27+
* @throws \Vianetz\Pdf\NoDataException
3028
*/
31-
public function setPdfFile($pdfFile);
29+
public function saveToFile(string $fileName): bool;
3230
}

src/Model/Document.php

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/Model/DocumentInterface.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/Model/EventManagerInterface.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
3-
* Event manager interface class
4-
*
55
* @section LICENSE
66
* This file is created by vianetz <[email protected]>.
77
* The code is distributed under the GPL license.
@@ -27,9 +27,7 @@ interface EventManagerInterface
2727
* Calls all observer callbacks registered for this event
2828
* and multiple observers matching event name pattern
2929
*
30-
* @param string $eventName
3130
* @param array<mixed,mixed> $data
32-
* @return void
3331
*/
34-
public function dispatch($eventName, array $data = []);
32+
public function dispatch(string $eventName, array $data = []): void;
3533
}

0 commit comments

Comments
 (0)