Skip to content

Commit fc77d44

Browse files
committed
Php8.5 Deprecation in Dompdf Handling of SVG
1 parent 5a03a03 commit fc77d44

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

samples/Sample_47_SVG.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22

33
use PhpOffice\PhpWord\Element\Section;
44
use PhpOffice\PhpWord\PhpWord;
5+
use PhpOffice\PhpWord\Settings;
56

67
include_once 'Sample_Header.php';
78

89
// New Word document
910
echo date('H:i:s'), ' Create new PhpWord object', EOL;
1011
$phpWord = new PhpWord();
1112

13+
// dompdf has deprecation problem for svg with Php8.5
14+
$rendererName = Settings::PDF_RENDERER_MPDF;
15+
$rendererLibraryPath = $vendorDirPath . '/mpdf/mpdf';
16+
Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
17+
1218
$section = $phpWord->addSection();
1319
$section->addText('SVG image without any styles:');
1420
$svg = $section->addImage(__DIR__ . '/resources/sample.svg');
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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\PhpWordTests\Writer\Word2007\Element;
20+
21+
use PhpOffice\PhpWord\PhpWord;
22+
use PhpOffice\PhpWordTests\TestHelperDOCX;
23+
24+
/**
25+
* Test class for PhpOffice\PhpWord\Writer\Word2007\Element subnamespace.
26+
*/
27+
class ImageSvgTest extends \PHPUnit\Framework\TestCase
28+
{
29+
private const CX = '6772275';
30+
private const CY = '3648075';
31+
32+
protected function tearDown(): void
33+
{
34+
TestHelperDOCX::clear();
35+
}
36+
37+
public function testStyleDimensionsZero(): void
38+
{
39+
$phpWord = new PhpWord();
40+
$section = $phpWord->addSection();
41+
$svg = $section->addImage(
42+
'samples/resources/sample.svg'
43+
);
44+
$svg->getStyle()->setWidth(0);
45+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
46+
$path = '/w:document/w:body/w:p[1]/w:r[1]/w:drawing/wp:inline/wp:extent';
47+
self::assertTrue($doc->elementExists($path));
48+
self::assertSame(
49+
self::CX,
50+
$doc->getElementAttribute($path, 'cx')
51+
);
52+
self::assertSame(
53+
self::CY,
54+
$doc->getElementAttribute($path, 'cy')
55+
);
56+
}
57+
58+
public function testNoStyle(): void
59+
{
60+
$phpWord = new PhpWord();
61+
$section = $phpWord->addSection();
62+
$svg = $section->addImage(
63+
'samples/resources/sample.svg'
64+
);
65+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
66+
$path = '/w:document/w:body/w:p[1]/w:r[1]/w:drawing/wp:inline/wp:extent';
67+
self::assertTrue($doc->elementExists($path));
68+
self::assertSame(
69+
self::CX,
70+
$doc->getElementAttribute($path, 'cx')
71+
);
72+
self::assertSame(
73+
self::CY,
74+
$doc->getElementAttribute($path, 'cy')
75+
);
76+
}
77+
}

0 commit comments

Comments
 (0)