Skip to content

Commit f9ce804

Browse files
settermjdProgi1984
andauthored
Extend the Options section of the PDF Writer documentation (#2642)
* Extend the Options section of the PDF Writer documentation When I used PHPWord to write a PDF document, recently, I followed the docs only to find that I also had to specify a PDF renderer — otherwise the operation failed. After a bit of research to figure out what to do to specify one, I thought it only right to document what I learned in the official documentation. * Update the docs changelog detailing the PDF Writer additions This change updates the changelog to include the enhancement made to the PDF Writer docs that show how to specify a PDF renderer when working with the PDF writer. * Fixed docs --------- Co-authored-by: Progi1984 <progi1984@gmail.com>
1 parent 2daa50c commit f9ce804

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

docs/changes/2.x/2.0.0.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
## Enhancements
66

77
- IOFactory : Added extractVariables method to extract variables from a document [@sibalonat](https://github.com/sibalonat) in [#2515](https://github.com/PHPOffice/PHPWord/pull/2515)
8+
- PDF Writer : Documented how to specify a PDF renderer, when working with the PDF writer, as well as the three available choices by [@settermjd](https://github.com/settermjd) in [#2642](https://github.com/PHPOffice/PHPWord/pull/2642)
89

910
### Bug fixes
1011

docs/usage/writers.md

+23
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,29 @@ $writer = IOFactory::createWriter($oPhpWord, 'PDF');
8787
$writer->save(__DIR__ . '/sample.pdf');
8888
```
8989

90+
#### Specify the PDF Renderer
91+
92+
Before PHPWord can write a PDF, you **must** specify the renderer to use and the path to it.
93+
Currently, three renderers are supported:
94+
95+
- [DomPDF](https://github.com/dompdf/dompdf)
96+
- [MPDF](https://mpdf.github.io/)
97+
- [TCPDF](https://tcpdf.org/)
98+
99+
To specify the renderer you use two static `Settings` functions:
100+
101+
- `setPdfRendererName`: This sets the name of the renderer library to use.
102+
Provide one of [`Settings`' three `PDF_` constants](https://github.com/PHPOffice/PHPWord/blob/master/src/PhpWord/Settings.php#L39-L41) to the function call.
103+
- `setPdfRendererPath`: This sets the path to the renderer library.
104+
This directory is the renderer's package directory within Composer's _vendor_ directory.
105+
106+
In the code below, you can see an example of setting MPDF as the desired PDF renderer.
107+
108+
```php
109+
Settings::setPdfRendererName(Settings::PDF_RENDERER_MPDF);
110+
Settings::setPdfRendererPath(__DIR__ . '/../vendor/mpdf/mpdf');
111+
```
112+
90113
## RTF
91114
The name of the writer is `RTF`.
92115

0 commit comments

Comments
 (0)