Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the Options section of the PDF Writer documentation #2642

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/2.x/2.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Enhancements

- IOFactory : Added extractVariables method to extract variables from a document [@sibalonat](https://github.com/sibalonat) in [#2515](https://github.com/PHPOffice/PHPWord/pull/2515)
- PDF Writer : Documented how to specify a PDF renderer, when working with the PDF writer, as well as the three available choices
Progi1984 marked this conversation as resolved.
Show resolved Hide resolved

### Bug fixes

Expand Down
23 changes: 23 additions & 0 deletions docs/usage/writers.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,29 @@ $writer = IOFactory::createWriter($oPhpWord, 'PDF');
$writer->save(__DIR__ . '/sample.pdf');
```

#### Specify the PDF Renderer

Before PHPWord can write a PDF, you **must** specify the renderer to use and the path to it.
Currently, three renderers are supported:

- [DomPDF](https://github.com/dompdf/dompdf)
- [MPDF](https://mpdf.github.io/)
- [TCPDF](https://tcpdf.org/)

To specify the renderer you use two static `Settings` functions:

- `setPdfRendererName`: This sets the name of the renderer library to use.
Provide one of [`Settings`' three `PDF_` constants](https://github.com/PHPOffice/PHPWord/blob/master/src/PhpWord/Settings.php#L39-L41) to the function call.
- `setPdfRendererPath`: This sets the path to the renderer library.
This directory is the renderer's package directory within Composer's _vendor_ directory.

In the code below, you can see an example of setting MPDF as the desired PDF renderer.

```php
Settings::setPdfRendererName(Settings::PDF_RENDERER_MPDF);
Settings::setPdfRendererPath(__DIR__ . '/../vendor/mpdf/mpdf');
```

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

Expand Down
Loading