From 016b8d6e9aa9600b33f1a8cb60c81eb81a982e79 Mon Sep 17 00:00:00 2001 From: Matthew Setter Date: Tue, 6 Aug 2024 10:29:56 +1000 Subject: [PATCH 1/3] Extend the Options section of the PDF Writer documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- docs/usage/writers.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/usage/writers.md b/docs/usage/writers.md index 81fb2b99b4..f561345a95 100644 --- a/docs/usage/writers.md +++ b/docs/usage/writers.md @@ -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`. From 7bf71314e8a1d068a2f08cf05db55412dd696cd7 Mon Sep 17 00:00:00 2001 From: Matthew Setter Date: Wed, 7 Aug 2024 10:49:35 +1000 Subject: [PATCH 2/3] 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. --- docs/changes/2.x/2.0.0.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changes/2.x/2.0.0.md b/docs/changes/2.x/2.0.0.md index c5fbaf4b52..f22163029b 100644 --- a/docs/changes/2.x/2.0.0.md +++ b/docs/changes/2.x/2.0.0.md @@ -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 ### Bug fixes From a31c94beb642c5c7968176a9a9fadf3d84b82f61 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Wed, 7 Aug 2024 08:16:55 +0200 Subject: [PATCH 3/3] Fixed docs --- docs/changes/2.x/2.0.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changes/2.x/2.0.0.md b/docs/changes/2.x/2.0.0.md index f22163029b..18f9267f39 100644 --- a/docs/changes/2.x/2.0.0.md +++ b/docs/changes/2.x/2.0.0.md @@ -5,7 +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 +- 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) ### Bug fixes