• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PHPOffice / PHPWord / 13461426829

21 Feb 2025 04:52PM UTC coverage: 96.905% (+0.1%) from 96.767%
13461426829

Pull #2567

github

web-flow
Merge e64a82db6 into 6ca8c9ff6
Pull Request #2567: WIP Do Not Install

300 of 307 new or added lines in 26 files covered. (97.72%)

161 existing lines in 21 files now uncovered.

12681 of 13086 relevant lines covered (96.91%)

37.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/src/PhpWord/Writer/PDF/DomPDF.php
1
<?php
2

3
/**
4
 * This file is part of PHPWord - A pure PHP library for reading and writing
5
 * word processing documents.
6
 *
7
 * PHPWord is free software distributed under the terms of the GNU Lesser
8
 * General Public License version 3 as published by the Free Software Foundation.
9
 *
10
 * For the full copyright and license information, please read the LICENSE
11
 * file that was distributed with this source code. For the full list of
12
 * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
13
 *
14
 * @see         https://github.com/PHPOffice/PhpWord
15
 *
16
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17
 */
18

19
namespace PhpOffice\PhpWord\Writer\PDF;
20

21
use Dompdf\Dompdf as DompdfLib;
22
use Dompdf\Options;
23
use PhpOffice\PhpWord\Writer\WriterInterface;
24

25
/**
26
 * DomPDF writer.
27
 *
28
 * @see  https://github.com/dompdf/dompdf
29
 * @since 0.10.0
30
 */
31
class DomPDF extends AbstractRenderer implements WriterInterface
32
{
33
    /**
34
     * Name of renderer include file.
35
     *
36
     * @var string
37
     */
38
    protected $includeFile;
39

40
    /**
41
     * Gets the implementation of external PDF library that should be used.
42
     *
43
     * @return Dompdf implementation
44
     */
45
    protected function createExternalWriterInstance()
46
    {
47
        $options = new Options();
2✔
48
        if ($this->getFont()) {
2✔
UNCOV
49
            $options->set('defaultFont', $this->getFont());
×
50
        }
51

52
        return new DompdfLib($options);
2✔
53
    }
54

55
    /**
56
     * Save PhpWord to file.
57
     */
58
    public function save(string $filename): void
59
    {
60
        $fileHandle = parent::prepareForSave($filename);
2✔
61

62
        //  PDF settings
63
        $paperSize = 'A4';
2✔
64
        $orientation = 'portrait';
2✔
65

66
        //  Create PDF
67
        $pdf = $this->createExternalWriterInstance();
2✔
68
        $pdf->setPaper(strtolower($paperSize), $orientation);
2✔
69
        $pdf->loadHtml(str_replace(PHP_EOL, '', $this->getContent()));
2✔
70
        $pdf->render();
2✔
71

72
        //  Write to file
73
        fwrite($fileHandle, $pdf->output());
2✔
74

75
        parent::restoreStateAfterSave($fileHandle);
2✔
76
    }
77
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc