Skip to content

Commit

Permalink
Merge pull request PHPOffice#2475 from oleibman/html_changes_5
Browse files Browse the repository at this point in the history
Add Support for Various Missing Features in HTML Writer
  • Loading branch information
Progi1984 authored Nov 22, 2023
2 parents d5ca5b4 + 4231051 commit 2c0488c
Show file tree
Hide file tree
Showing 120 changed files with 3,117 additions and 708 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"ext-dom": "*",
"ext-json": "*",
"ext-xml": "*",
"laminas/laminas-escaper": ">=2.6",
"phpoffice/math": "^0.1"
},
"require-dev": {
Expand Down
62 changes: 0 additions & 62 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion docs/changes/1.x/1.2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
- 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)
- 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)
- 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)
- Add Support for Various Missing Features in HTML Writer by [@oleibman](https://github.com/oleibman) in [#2475](https://github.com/PHPOffice/PHPWord/pull/2475)
- Fixed addHTML (text-align:right in html is not handled correctly) in [#2467](https://github.com/PHPOffice/PHPWord/pull/2467)
- HTML Writer : Added ability to specify generic fallback font
- HTML Writer : Added ability to specify handling of whitespace
- HTML Writer : Added support for Table Border style, color, and size
- HTML Writer : Added support for empty paragraphs (Word writer permits, browsers generally suppress)
- HTML Writer : Paragraph style should support indentation, line-height, page-break-before
- HTML Writer : Removed margin-top/bottom when spacing is null in Paragraph style
- HTML Writer : Added default paragraph style to all paragraphs, as well as class Normal
- HTML Writer : Use css @page and page declarations for sections
- HTML Writer : Wrap sections in div, with page break before each (except first)
- PDF Writer : Added support for PageBreak
- PDF Writer : Added callback for modifying the HTML
- Added Support for Language, both for document overall and individual text elements

### Bug fixes

Expand All @@ -41,4 +55,8 @@
- 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)
- 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)
- 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)
- 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)
- 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)


### BC Breaks
- Removed dependency `laminas/laminas-escaper`
4 changes: 3 additions & 1 deletion docs/usage/styles/font.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ Available Font style options:
- ``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
See ``\PhpOffice\PhpWord\Style\Language`` class for some language codes.
- ``position``. The text position, raised or lowered, in half points
- ``hidden``. Hidden text, *true* or *false*.
- ``hidden``. Hidden text, *true* or *false*.
- ``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).
- ``fallbackFont``. Fallback generic font for html/pdf. Possible values are *sans-serif*, *serif*, and *monospace* (other css values for generic fonts are accepted).
37 changes: 37 additions & 0 deletions docs/usage/writers.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ $writer = IOFactory::createWriter($oPhpWord, 'HTML');
$writer->save(__DIR__ . '/sample.html');
```


When generating html/pdf, you can alter the default handling of white space (normal), and/or supply a fallback generic font as follows:

```php
$writer = IOFactory::createWriter($oPhpWord, 'HTML');
$writer->setDefaultGenericFont('serif');
$writer->setDefaultWhiteSpace('pre-wrap');
$writer->save(__DIR__ . '/sample.html');
```

## ODText
The name of the writer is `ODText`.

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

To generate a PDF, the PhpWord object passes through HTML before generating the PDF.
This HTML can be modified using a callback.

``` php
<?php

$writer = IOFactory::createWriter($oPhpWord, 'PDF');
$writer->setEditCallback('cbEditHTML');
$writer->save(__DIR__ . '/sample.pdf');

/**
* Add a meta tag generator
*/
function cbEditHTML(string $inputHTML): string
{
$beforeBody = '<meta name="generator" content="PHPWord" />';
$needle = '</head>';

$pos = strpos($inputHTML, $needle);
if ($pos !== false) {
$inputHTML = (string) substr_replace($inputHTML, "$beforeBody\n$needle", $pos, strlen($needle));
}

return $inputHTML;
}
```

### Options

You can define options like :
Expand Down
Loading

0 comments on commit 2c0488c

Please sign in to comment.