Skip to content

Commit 2c0488c

Browse files
authored
Merge pull request #2475 from oleibman/html_changes_5
Add Support for Various Missing Features in HTML Writer
2 parents d5ca5b4 + 4231051 commit 2c0488c

File tree

120 files changed

+3117
-708
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+3117
-708
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
"ext-dom": "*",
6969
"ext-json": "*",
7070
"ext-xml": "*",
71-
"laminas/laminas-escaper": ">=2.6",
7271
"phpoffice/math": "^0.1"
7372
},
7473
"require-dev": {

composer.lock

Lines changed: 0 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/changes/1.x/1.2.0.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@
1515
- Word2007 Reader/Writer: Permit book-fold printing by [@potofcoffee](https://github.com/potofcoffee) in [#2225](https://github.com/PHPOffice/PHPWord/pull/2225) & [#2470](https://github.com/PHPOffice/PHPWord/pull/2470)
1616
- Word2007 Writer : Add PageNumber to TOC by [@jet-desk](https://github.com/jet-desk) in [#1652](https://github.com/PHPOffice/PHPWord/pull/1652) & [#2471](https://github.com/PHPOffice/PHPWord/pull/2471)
1717
- Word2007 Reader/Writer + ODText Reader/Writer : Add Element Formula in by [@Progi1984](https://github.com/Progi1984) in [#2477](https://github.com/PHPOffice/PHPWord/pull/2477)
18+
- Add Support for Various Missing Features in HTML Writer by [@oleibman](https://github.com/oleibman) in [#2475](https://github.com/PHPOffice/PHPWord/pull/2475)
19+
- Fixed addHTML (text-align:right in html is not handled correctly) in [#2467](https://github.com/PHPOffice/PHPWord/pull/2467)
20+
- HTML Writer : Added ability to specify generic fallback font
21+
- HTML Writer : Added ability to specify handling of whitespace
22+
- HTML Writer : Added support for Table Border style, color, and size
23+
- HTML Writer : Added support for empty paragraphs (Word writer permits, browsers generally suppress)
24+
- HTML Writer : Paragraph style should support indentation, line-height, page-break-before
25+
- HTML Writer : Removed margin-top/bottom when spacing is null in Paragraph style
26+
- HTML Writer : Added default paragraph style to all paragraphs, as well as class Normal
27+
- HTML Writer : Use css @page and page declarations for sections
28+
- HTML Writer : Wrap sections in div, with page break before each (except first)
29+
- PDF Writer : Added support for PageBreak
30+
- PDF Writer : Added callback for modifying the HTML
31+
- Added Support for Language, both for document overall and individual text elements
1832

1933
### Bug fixes
2034

@@ -41,4 +55,8 @@
4155
- Bump phpunit/phpunit from 9.6.11 to 9.6.13 by [@dependabot](https://github.com/dependabot) in [#2481](https://github.com/PHPOffice/PHPWord/pull/2481)
4256
- Bump tecnickcom/tcpdf from 6.6.2 to 6.6.5 by [@dependabot](https://github.com/dependabot) in [#2482](https://github.com/PHPOffice/PHPWord/pull/2482)
4357
- Bump phpmd/phpmd from 2.13.0 to 2.14.1 by [@dependabot](https://github.com/dependabot) in [#2483](https://github.com/PHPOffice/PHPWord/pull/2483)
44-
- Bump phpstan/phpstan-phpunit from 1.3.14 to 1.3.15 by [@dependabot](https://github.com/dependabot) in [#2494](https://github.com/PHPOffice/PHPWord/pull/2494)
58+
- Bump phpstan/phpstan-phpunit from 1.3.14 to 1.3.15 by [@dependabot](https://github.com/dependabot) in [#2494](https://github.com/PHPOffice/PHPWord/pull/2494)
59+
60+
61+
### BC Breaks
62+
- Removed dependency `laminas/laminas-escaper`

docs/usage/styles/font.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ Available Font style options:
2323
- ``lang``. Language, either a language code like *en-US*, *fr-BE*, etc. or an object (or as an array) if you need to set eastAsian or bidirectional languages
2424
See ``\PhpOffice\PhpWord\Style\Language`` class for some language codes.
2525
- ``position``. The text position, raised or lowered, in half points
26-
- ``hidden``. Hidden text, *true* or *false*.
26+
- ``hidden``. Hidden text, *true* or *false*.
27+
- ``whiteSpace``. How white space is handled when generating html/pdf. Possible values are *pre-wrap* and *normal* (other css values for white space are accepted, but are not expected to be useful).
28+
- ``fallbackFont``. Fallback generic font for html/pdf. Possible values are *sans-serif*, *serif*, and *monospace* (other css values for generic fonts are accepted).

docs/usage/writers.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ $writer = IOFactory::createWriter($oPhpWord, 'HTML');
1010
$writer->save(__DIR__ . '/sample.html');
1111
```
1212

13+
14+
When generating html/pdf, you can alter the default handling of white space (normal), and/or supply a fallback generic font as follows:
15+
16+
```php
17+
$writer = IOFactory::createWriter($oPhpWord, 'HTML');
18+
$writer->setDefaultGenericFont('serif');
19+
$writer->setDefaultWhiteSpace('pre-wrap');
20+
$writer->save(__DIR__ . '/sample.html');
21+
```
22+
1323
## ODText
1424
The name of the writer is `ODText`.
1525

@@ -30,6 +40,33 @@ $writer = IOFactory::createWriter($oPhpWord, 'PDF');
3040
$writer->save(__DIR__ . '/sample.pdf');
3141
```
3242

43+
To generate a PDF, the PhpWord object passes through HTML before generating the PDF.
44+
This HTML can be modified using a callback.
45+
46+
``` php
47+
<?php
48+
49+
$writer = IOFactory::createWriter($oPhpWord, 'PDF');
50+
$writer->setEditCallback('cbEditHTML');
51+
$writer->save(__DIR__ . '/sample.pdf');
52+
53+
/**
54+
* Add a meta tag generator
55+
*/
56+
function cbEditHTML(string $inputHTML): string
57+
{
58+
$beforeBody = '<meta name="generator" content="PHPWord" />';
59+
$needle = '</head>';
60+
61+
$pos = strpos($inputHTML, $needle);
62+
if ($pos !== false) {
63+
$inputHTML = (string) substr_replace($inputHTML, "$beforeBody\n$needle", $pos, strlen($needle));
64+
}
65+
66+
return $inputHTML;
67+
}
68+
```
69+
3370
### Options
3471

3572
You can define options like :

0 commit comments

Comments
 (0)