-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06-css-inlining.php
More file actions
30 lines (23 loc) · 1.01 KB
/
Copy path06-css-inlining.php
File metadata and controls
30 lines (23 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
declare(strict_types=1);
// Stylesheets and classes: fromHtmlWithStyles() resolves <style> blocks
// and CSS classes into inline styles before parsing. Needs the optional
// suggested package: composer require tijsverkoyen/css-to-inline-styles
require __DIR__.'/bootstrap.php';
use Dskripchenko\PhpDocx\Html\Converter;
use Dskripchenko\PhpDocx\Writer\Word2007Writer;
if (! class_exists(\TijsVerkoyen\CssToInlineStyles\CssToInlineStyles::class)) {
fwrite(STDERR, "skipped: composer require tijsverkoyen/css-to-inline-styles\n");
exit(0);
}
$document = (new Converter)->fromHtmlWithStyles(<<<'HTML'
<style>
h1 { color: #2c3e50; }
.brand { color: #c0392b; font-weight: bold; }
.fineprint{ font-size: 8pt; color: #888888; }
</style>
<h1>Styled with a stylesheet</h1>
<p>Delivered by <span class="brand">Acme Corp</span>.</p>
<p class="fineprint">Terms and conditions apply.</p>
HTML);
save_sample('06-css-inlining.docx', (new Word2007Writer)->write($document));