Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
DocumentWriter | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
toPdfString | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package phpOMS\Utils\Parser\Document |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace phpOMS\Utils\Parser\Document; |
16 | |
17 | use PhpOffice\PhpWord\PhpWord; |
18 | use PhpOffice\PhpWord\Settings; |
19 | use PhpOffice\PhpWord\Writer\PDF\AbstractRenderer; |
20 | use PhpOffice\PhpWord\Writer\WriterInterface; |
21 | |
22 | /** |
23 | * Save word document |
24 | * |
25 | * @package phpOMS\Utils\Parser\Document |
26 | * @license OMS License 2.0 |
27 | * @link https://jingga.app |
28 | * @since 1.0.0 |
29 | */ |
30 | class DocumentWriter extends AbstractRenderer implements WriterInterface |
31 | { |
32 | /** |
33 | * Save PhpWord to file. |
34 | * |
35 | * @param string $filename Name of the file to save as |
36 | * |
37 | * @return string |
38 | * |
39 | * @since 1.0.0 |
40 | */ |
41 | public function toPdfString($filename = null) : string |
42 | { |
43 | // PDF settings |
44 | $paperSize = \strtoupper('A4'); |
45 | $orientation = \strtoupper('portrait'); |
46 | |
47 | // Create PDF |
48 | $pdf = new \Mpdf\Mpdf(); |
49 | $pdf->_setPageSize($paperSize, $orientation); |
50 | $pdf->addPage($orientation); |
51 | |
52 | // Write document properties |
53 | $phpWord = $this->getPhpWord(); |
54 | $docProps = $phpWord->getDocInfo(); |
55 | $pdf->setTitle($docProps->getTitle()); |
56 | $pdf->setAuthor($docProps->getCreator()); |
57 | $pdf->setSubject($docProps->getSubject()); |
58 | $pdf->setKeywords($docProps->getKeywords()); |
59 | $pdf->setCreator($docProps->getCreator()); |
60 | |
61 | $pdf->writeHTML($this->getContent()); |
62 | |
63 | // Write to file |
64 | return $pdf->output($filename, 'S'); |
65 | } |
66 | } |