From 5103732b7b635ce7eacfec06678c7916937e789d Mon Sep 17 00:00:00 2001 From: boshi_no_1 Date: Fri, 24 May 2024 10:14:55 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E4=B8=BAPHPWord=E7=9A=84MPDF=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=B7=BB=E5=8A=A0config=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E5=85=B6=E5=8F=AF=E4=BB=A5=E6=AD=A3=E5=B8=B8=E8=A2=AB?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/IOFactory.php | 5 ++--- src/PhpWord/Writer/PDF.php | 4 ++-- src/PhpWord/Writer/PDF/AbstractRenderer.php | 5 ++++- src/PhpWord/Writer/PDF/MPDF.php | 6 +++--- tests/PhpWordTests/Writer/PDF/MPDFTest.php | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/PhpWord/IOFactory.php b/src/PhpWord/IOFactory.php index 9ceb7026a3..1212c4a0a3 100644 --- a/src/PhpWord/IOFactory.php +++ b/src/PhpWord/IOFactory.php @@ -33,15 +33,14 @@ abstract class IOFactory * * @return WriterInterface */ - public static function createWriter(PhpWord $phpWord, $name = 'Word2007') + public static function createWriter(PhpWord $phpWord, $name = 'Word2007', $config = []) { if ($name !== 'WriterInterface' && !in_array($name, ['ODText', 'RTF', 'Word2007', 'HTML', 'PDF'], true)) { throw new Exception("\"{$name}\" is not a valid writer."); } $fqName = "PhpOffice\\PhpWord\\Writer\\{$name}"; - - return new $fqName($phpWord); + return new $fqName($phpWord, $config); } /** diff --git a/src/PhpWord/Writer/PDF.php b/src/PhpWord/Writer/PDF.php index f937f599c1..46930cf9c2 100644 --- a/src/PhpWord/Writer/PDF.php +++ b/src/PhpWord/Writer/PDF.php @@ -39,7 +39,7 @@ class PDF /** * Instantiate a new renderer of the configured type within this container class. */ - public function __construct(PhpWord $phpWord) + public function __construct(PhpWord $phpWord, $config = []) { $pdfLibraryName = Settings::getPdfRendererName(); $pdfLibraryPath = Settings::getPdfRendererPath(); @@ -54,7 +54,7 @@ public function __construct(PhpWord $phpWord) } $rendererName = static::class . '\\' . $pdfLibraryName; - $this->renderer = new $rendererName($phpWord); + $this->renderer = new $rendererName($phpWord, $config); } /** diff --git a/src/PhpWord/Writer/PDF/AbstractRenderer.php b/src/PhpWord/Writer/PDF/AbstractRenderer.php index c143a6cb5c..246d3dfbbb 100644 --- a/src/PhpWord/Writer/PDF/AbstractRenderer.php +++ b/src/PhpWord/Writer/PDF/AbstractRenderer.php @@ -73,14 +73,17 @@ abstract class AbstractRenderer extends HTML 9 => 'A4', // (210 mm by 297 mm) ]; + protected $config; + /** * Create new instance. * * @param PhpWord $phpWord PhpWord object */ - public function __construct(PhpWord $phpWord) + public function __construct(PhpWord $phpWord, $config = []) { parent::__construct($phpWord); + $this->config = $config; $this->isPdf = true; if ($this->includeFile != null) { $includeFile = Settings::getPdfRendererPath() . '/' . $this->includeFile; diff --git a/src/PhpWord/Writer/PDF/MPDF.php b/src/PhpWord/Writer/PDF/MPDF.php index 311f743d6d..80ddf78eff 100644 --- a/src/PhpWord/Writer/PDF/MPDF.php +++ b/src/PhpWord/Writer/PDF/MPDF.php @@ -37,13 +37,13 @@ class MPDF extends AbstractRenderer implements WriterInterface * * @codeCoverageIgnore */ - public function __construct(PhpWord $phpWord) + public function __construct(PhpWord $phpWord, $config = []) { if (file_exists(Settings::getPdfRendererPath() . '/mpdf.php')) { // MPDF version 5.* needs this file to be included, later versions not $this->includeFile = 'mpdf.php'; } - parent::__construct($phpWord); + parent::__construct($phpWord, $config); } /** @@ -55,7 +55,7 @@ protected function createExternalWriterInstance() { $mPdfClass = $this->getMPdfClassName(); - $options = []; + $options = $this->config; if ($this->getFont()) { $options['default_font'] = $this->getFont(); } diff --git a/tests/PhpWordTests/Writer/PDF/MPDFTest.php b/tests/PhpWordTests/Writer/PDF/MPDFTest.php index 0fe53456ba..809c2d2522 100644 --- a/tests/PhpWordTests/Writer/PDF/MPDFTest.php +++ b/tests/PhpWordTests/Writer/PDF/MPDFTest.php @@ -46,7 +46,7 @@ public function testConstruct(): void $section = $phpWord->addSection($oSettings); // @phpstan-ignore-line $section->addText('Section 2 - landscape'); - $writer = new MPDF($phpWord); + $writer = new MPDF($phpWord, ['mode' => 'zh-cn', 'margin_top' => 28]); $writer->save($file); self::assertFileExists($file); From 24393acfe47f54dd6b2b2accb021f552149599ca Mon Sep 17 00:00:00 2001 From: boshi_no_1 Date: Fri, 24 May 2024 10:21:37 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E4=B8=BAPHPWord=E7=9A=84MPDF=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=B7=BB=E5=8A=A0config=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E5=85=B6=E5=8F=AF=E4=BB=A5=E6=AD=A3=E5=B8=B8=E8=A2=AB?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/IOFactory.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/IOFactory.php b/src/PhpWord/IOFactory.php index 1212c4a0a3..7684e98992 100644 --- a/src/PhpWord/IOFactory.php +++ b/src/PhpWord/IOFactory.php @@ -40,7 +40,10 @@ public static function createWriter(PhpWord $phpWord, $name = 'Word2007', $confi } $fqName = "PhpOffice\\PhpWord\\Writer\\{$name}"; - return new $fqName($phpWord, $config); + if ($fqName == 'PDF') { + return new $fqName($phpWord, $config); + } + return new $fqName($phpWord); } /** From 2d0dbe5896068c4a90a972c858a48c88cf2cbd4b Mon Sep 17 00:00:00 2001 From: boshi_no_1 Date: Fri, 24 May 2024 10:27:36 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E4=B8=BAPHPWord=E7=9A=84MPDF=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=B7=BB=E5=8A=A0config=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E5=85=B6=E5=8F=AF=E4=BB=A5=E6=AD=A3=E5=B8=B8=E8=A2=AB?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/IOFactory.php | 3 ++- src/PhpWord/Writer/PDF.php | 2 ++ src/PhpWord/Writer/PDF/AbstractRenderer.php | 4 ++++ src/PhpWord/Writer/PDF/MPDF.php | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/IOFactory.php b/src/PhpWord/IOFactory.php index 7684e98992..ca2c7fcd83 100644 --- a/src/PhpWord/IOFactory.php +++ b/src/PhpWord/IOFactory.php @@ -30,6 +30,7 @@ abstract class IOFactory * Create new writer. * * @param string $name + * @param array $config * * @return WriterInterface */ @@ -40,7 +41,7 @@ public static function createWriter(PhpWord $phpWord, $name = 'Word2007', $confi } $fqName = "PhpOffice\\PhpWord\\Writer\\{$name}"; - if ($fqName == 'PDF') { + if ($name === 'PDF') { return new $fqName($phpWord, $config); } return new $fqName($phpWord); diff --git a/src/PhpWord/Writer/PDF.php b/src/PhpWord/Writer/PDF.php index 46930cf9c2..2cbe80793c 100644 --- a/src/PhpWord/Writer/PDF.php +++ b/src/PhpWord/Writer/PDF.php @@ -38,6 +38,8 @@ class PDF /** * Instantiate a new renderer of the configured type within this container class. + * + * @param array $config */ public function __construct(PhpWord $phpWord, $config = []) { diff --git a/src/PhpWord/Writer/PDF/AbstractRenderer.php b/src/PhpWord/Writer/PDF/AbstractRenderer.php index 246d3dfbbb..e8c24cacbc 100644 --- a/src/PhpWord/Writer/PDF/AbstractRenderer.php +++ b/src/PhpWord/Writer/PDF/AbstractRenderer.php @@ -73,6 +73,10 @@ abstract class AbstractRenderer extends HTML 9 => 'A4', // (210 mm by 297 mm) ]; + /** + * config in MPDF + * @var array|mixed + */ protected $config; /** diff --git a/src/PhpWord/Writer/PDF/MPDF.php b/src/PhpWord/Writer/PDF/MPDF.php index 80ddf78eff..8f22a8007e 100644 --- a/src/PhpWord/Writer/PDF/MPDF.php +++ b/src/PhpWord/Writer/PDF/MPDF.php @@ -35,6 +35,7 @@ class MPDF extends AbstractRenderer implements WriterInterface /** * Overridden to set the correct includefile, only needed for MPDF 5. * + * @param array $config * @codeCoverageIgnore */ public function __construct(PhpWord $phpWord, $config = []) From 2909201049fd09a7f1c231b1fa9da1cdf7bf65da Mon Sep 17 00:00:00 2001 From: boshi_no_1 Date: Fri, 24 May 2024 10:34:41 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E4=B8=BAPHPWord=E7=9A=84MPDF=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=B7=BB=E5=8A=A0config=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E5=85=B6=E5=8F=AF=E4=BB=A5=E6=AD=A3=E5=B8=B8=E8=A2=AB?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/Writer/PDF/AbstractRenderer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PhpWord/Writer/PDF/AbstractRenderer.php b/src/PhpWord/Writer/PDF/AbstractRenderer.php index e8c24cacbc..d3d452a710 100644 --- a/src/PhpWord/Writer/PDF/AbstractRenderer.php +++ b/src/PhpWord/Writer/PDF/AbstractRenderer.php @@ -83,6 +83,7 @@ abstract class AbstractRenderer extends HTML * Create new instance. * * @param PhpWord $phpWord PhpWord object + * @param array $config */ public function __construct(PhpWord $phpWord, $config = []) { From ac2580067e875881c32a7aaafd98846a708d653a Mon Sep 17 00:00:00 2001 From: boshi_no_1 Date: Fri, 24 May 2024 10:37:43 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E4=B8=BAPHPWord=E7=9A=84MPDF=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=B7=BB=E5=8A=A0config=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E5=85=B6=E5=8F=AF=E4=BB=A5=E6=AD=A3=E5=B8=B8=E8=A2=AB?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/IOFactory.php | 1 + src/PhpWord/Writer/PDF/AbstractRenderer.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/IOFactory.php b/src/PhpWord/IOFactory.php index ca2c7fcd83..ce169a1cdc 100644 --- a/src/PhpWord/IOFactory.php +++ b/src/PhpWord/IOFactory.php @@ -44,6 +44,7 @@ public static function createWriter(PhpWord $phpWord, $name = 'Word2007', $confi if ($name === 'PDF') { return new $fqName($phpWord, $config); } + return new $fqName($phpWord); } diff --git a/src/PhpWord/Writer/PDF/AbstractRenderer.php b/src/PhpWord/Writer/PDF/AbstractRenderer.php index d3d452a710..3447269b40 100644 --- a/src/PhpWord/Writer/PDF/AbstractRenderer.php +++ b/src/PhpWord/Writer/PDF/AbstractRenderer.php @@ -74,7 +74,8 @@ abstract class AbstractRenderer extends HTML ]; /** - * config in MPDF + * config in MPDF. + * * @var array|mixed */ protected $config; From 3c8de7f59d78b8bec03ea0a78838fa70b994554c Mon Sep 17 00:00:00 2001 From: boshi_no_1 Date: Fri, 24 May 2024 13:14:39 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E4=B8=BAPHPWord=E7=9A=84MPDF=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=B7=BB=E5=8A=A0config=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E5=85=B6=E5=8F=AF=E4=BB=A5=E6=AD=A3=E5=B8=B8=E8=A2=AB?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/IOFactory.php | 5 +---- src/PhpWord/Writer/HTML.php | 4 +++- src/PhpWord/Writer/ODText.php | 4 +++- src/PhpWord/Writer/PDF/AbstractRenderer.php | 2 +- src/PhpWord/Writer/RTF.php | 4 +++- src/PhpWord/Writer/Word2007.php | 3 ++- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/PhpWord/IOFactory.php b/src/PhpWord/IOFactory.php index ce169a1cdc..41c4f300c4 100644 --- a/src/PhpWord/IOFactory.php +++ b/src/PhpWord/IOFactory.php @@ -41,11 +41,8 @@ public static function createWriter(PhpWord $phpWord, $name = 'Word2007', $confi } $fqName = "PhpOffice\\PhpWord\\Writer\\{$name}"; - if ($name === 'PDF') { - return new $fqName($phpWord, $config); - } - return new $fqName($phpWord); + return new $fqName($phpWord, $config); } /** diff --git a/src/PhpWord/Writer/HTML.php b/src/PhpWord/Writer/HTML.php index 647890591d..b1d3bb7664 100644 --- a/src/PhpWord/Writer/HTML.php +++ b/src/PhpWord/Writer/HTML.php @@ -68,8 +68,10 @@ class HTML extends AbstractWriter implements WriterInterface /** * Create new instance. + * + * @param array $config */ - public function __construct(?PhpWord $phpWord = null) + public function __construct(?PhpWord $phpWord = null, $config = []) { $this->setPhpWord($phpWord); diff --git a/src/PhpWord/Writer/ODText.php b/src/PhpWord/Writer/ODText.php index 616119e5cc..5b53a8ffec 100644 --- a/src/PhpWord/Writer/ODText.php +++ b/src/PhpWord/Writer/ODText.php @@ -38,8 +38,10 @@ class ODText extends AbstractWriter implements WriterInterface /** * Create new ODText writer. + * + * @param array $config */ - public function __construct(?PhpWord $phpWord = null) + public function __construct(?PhpWord $phpWord = null, $config = []) { // Assign PhpWord $this->setPhpWord($phpWord); diff --git a/src/PhpWord/Writer/PDF/AbstractRenderer.php b/src/PhpWord/Writer/PDF/AbstractRenderer.php index 3447269b40..8b777b69fd 100644 --- a/src/PhpWord/Writer/PDF/AbstractRenderer.php +++ b/src/PhpWord/Writer/PDF/AbstractRenderer.php @@ -75,7 +75,7 @@ abstract class AbstractRenderer extends HTML /** * config in MPDF. - * + * * @var array|mixed */ protected $config; diff --git a/src/PhpWord/Writer/RTF.php b/src/PhpWord/Writer/RTF.php index 0a04d4f53e..12db2043cd 100644 --- a/src/PhpWord/Writer/RTF.php +++ b/src/PhpWord/Writer/RTF.php @@ -35,8 +35,10 @@ class RTF extends AbstractWriter implements WriterInterface /** * Create new instance. + * + * @param array $config */ - public function __construct(?PhpWord $phpWord = null) + public function __construct(?PhpWord $phpWord = null, $config = []) { $this->setPhpWord($phpWord); diff --git a/src/PhpWord/Writer/Word2007.php b/src/PhpWord/Writer/Word2007.php index ab4fd1e3eb..ab3e48f254 100644 --- a/src/PhpWord/Writer/Word2007.php +++ b/src/PhpWord/Writer/Word2007.php @@ -45,8 +45,9 @@ class Word2007 extends AbstractWriter implements WriterInterface * Create new Word2007 writer. * * @param \PhpOffice\PhpWord\PhpWord + * @param array $config */ - public function __construct(?PhpWord $phpWord = null) + public function __construct(?PhpWord $phpWord = null, $config = []) { // Assign PhpWord $this->setPhpWord($phpWord); From 9eaabcfc05065cb144d9749ad52009020f892e63 Mon Sep 17 00:00:00 2001 From: boshi_no_1 Date: Fri, 24 May 2024 13:32:49 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E4=B8=BAPHPWord=E7=9A=84MPDF=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=B7=BB=E5=8A=A0config=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E5=85=B6=E5=8F=AF=E4=BB=A5=E6=AD=A3=E5=B8=B8=E8=A2=AB?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/Writer/AbstractWriter.php | 14 ++++++++++++++ src/PhpWord/Writer/HTML.php | 3 ++- src/PhpWord/Writer/ODText.php | 2 +- src/PhpWord/Writer/PDF.php | 2 +- src/PhpWord/Writer/RTF.php | 3 ++- src/PhpWord/Writer/Word2007.php | 6 ++++-- 6 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/PhpWord/Writer/AbstractWriter.php b/src/PhpWord/Writer/AbstractWriter.php index 8ebf98c7b5..61e7963571 100644 --- a/src/PhpWord/Writer/AbstractWriter.php +++ b/src/PhpWord/Writer/AbstractWriter.php @@ -93,6 +93,20 @@ abstract class AbstractWriter implements WriterInterface */ private $tempFilename; + /** + * some options in config + * + * @var array + */ + protected $config; + + public function __construct(?PhpWord $phpWord = null, $config = []) + { + $this->setPhpWord($phpWord); + $this->config = $config; + } + + /** * Get PhpWord object. * diff --git a/src/PhpWord/Writer/HTML.php b/src/PhpWord/Writer/HTML.php index b1d3bb7664..071eebd4f6 100644 --- a/src/PhpWord/Writer/HTML.php +++ b/src/PhpWord/Writer/HTML.php @@ -73,7 +73,8 @@ class HTML extends AbstractWriter implements WriterInterface */ public function __construct(?PhpWord $phpWord = null, $config = []) { - $this->setPhpWord($phpWord); + // Assign PhpWord + parent::__construct($phpWord, $config); $this->parts = ['Head', 'Body']; foreach ($this->parts as $partName) { diff --git a/src/PhpWord/Writer/ODText.php b/src/PhpWord/Writer/ODText.php index 5b53a8ffec..e367362b9d 100644 --- a/src/PhpWord/Writer/ODText.php +++ b/src/PhpWord/Writer/ODText.php @@ -44,7 +44,7 @@ class ODText extends AbstractWriter implements WriterInterface public function __construct(?PhpWord $phpWord = null, $config = []) { // Assign PhpWord - $this->setPhpWord($phpWord); + parent::__construct($phpWord, $config); // Create parts $this->parts = [ diff --git a/src/PhpWord/Writer/PDF.php b/src/PhpWord/Writer/PDF.php index 2cbe80793c..755c73f933 100644 --- a/src/PhpWord/Writer/PDF.php +++ b/src/PhpWord/Writer/PDF.php @@ -27,7 +27,7 @@ * * @since 0.10.0 */ -class PDF +class PDF implements WriterInterface { /** * The wrapper for the requested PDF rendering engine. diff --git a/src/PhpWord/Writer/RTF.php b/src/PhpWord/Writer/RTF.php index 12db2043cd..7f0ad84075 100644 --- a/src/PhpWord/Writer/RTF.php +++ b/src/PhpWord/Writer/RTF.php @@ -40,7 +40,8 @@ class RTF extends AbstractWriter implements WriterInterface */ public function __construct(?PhpWord $phpWord = null, $config = []) { - $this->setPhpWord($phpWord); + // Assign PhpWord + parent::__construct($phpWord, $config); $this->parts = ['Header', 'Document']; foreach ($this->parts as $partName) { diff --git a/src/PhpWord/Writer/Word2007.php b/src/PhpWord/Writer/Word2007.php index ab3e48f254..b374086c27 100644 --- a/src/PhpWord/Writer/Word2007.php +++ b/src/PhpWord/Writer/Word2007.php @@ -18,6 +18,7 @@ namespace PhpOffice\PhpWord\Writer; use PhpOffice\PhpWord\Element\Section; +use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Media; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Shared\ZipArchive; @@ -44,13 +45,13 @@ class Word2007 extends AbstractWriter implements WriterInterface /** * Create new Word2007 writer. * - * @param \PhpOffice\PhpWord\PhpWord + * @param \PhpOffice\PhpWord\PhpWord $phpWord * @param array $config */ public function __construct(?PhpWord $phpWord = null, $config = []) { // Assign PhpWord - $this->setPhpWord($phpWord); + parent::__construct($phpWord, $config); // Create parts // The first four files need to be in this order for Mimetype detection to work @@ -253,6 +254,7 @@ private function addNotes(ZipArchive $zip, &$rId, $noteType = 'footnote'): void * Add comments. * * @param int &$rId + * @throws Exception */ private function addComments(ZipArchive $zip, &$rId): void { From 4f76ca73a334356df445e0c7cd16b7add704cb6c Mon Sep 17 00:00:00 2001 From: boshi_no_1 Date: Fri, 24 May 2024 13:34:43 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E4=B8=BAPHPWord=E7=9A=84MPDF=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=B7=BB=E5=8A=A0config=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E5=85=B6=E5=8F=AF=E4=BB=A5=E6=AD=A3=E5=B8=B8=E8=A2=AB?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/Writer/AbstractWriter.php | 3 +-- src/PhpWord/Writer/Word2007.php | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/PhpWord/Writer/AbstractWriter.php b/src/PhpWord/Writer/AbstractWriter.php index 61e7963571..dc7f09de0f 100644 --- a/src/PhpWord/Writer/AbstractWriter.php +++ b/src/PhpWord/Writer/AbstractWriter.php @@ -94,7 +94,7 @@ abstract class AbstractWriter implements WriterInterface private $tempFilename; /** - * some options in config + * some options in config. * * @var array */ @@ -106,7 +106,6 @@ public function __construct(?PhpWord $phpWord = null, $config = []) $this->config = $config; } - /** * Get PhpWord object. * diff --git a/src/PhpWord/Writer/Word2007.php b/src/PhpWord/Writer/Word2007.php index b374086c27..32c58d0d30 100644 --- a/src/PhpWord/Writer/Word2007.php +++ b/src/PhpWord/Writer/Word2007.php @@ -18,7 +18,6 @@ namespace PhpOffice\PhpWord\Writer; use PhpOffice\PhpWord\Element\Section; -use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Media; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Shared\ZipArchive; @@ -254,7 +253,6 @@ private function addNotes(ZipArchive $zip, &$rId, $noteType = 'footnote'): void * Add comments. * * @param int &$rId - * @throws Exception */ private function addComments(ZipArchive $zip, &$rId): void { From 20b2c1a725bf83d14561c9261a3f10d4c6520522 Mon Sep 17 00:00:00 2001 From: boshi_no_1 Date: Fri, 24 May 2024 13:42:54 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E4=B8=BAPHPWord=E7=9A=84MPDF=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=B7=BB=E5=8A=A0config=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E5=85=B6=E5=8F=AF=E4=BB=A5=E6=AD=A3=E5=B8=B8=E8=A2=AB?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/IOFactory.php | 2 +- src/PhpWord/Writer/AbstractWriter.php | 6 ++++++ src/PhpWord/Writer/PDF/AbstractRenderer.php | 14 ++++---------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/PhpWord/IOFactory.php b/src/PhpWord/IOFactory.php index 41c4f300c4..4f84cbb33b 100644 --- a/src/PhpWord/IOFactory.php +++ b/src/PhpWord/IOFactory.php @@ -34,7 +34,7 @@ abstract class IOFactory * * @return WriterInterface */ - public static function createWriter(PhpWord $phpWord, $name = 'Word2007', $config = []) + public static function createWriter(PhpWord $phpWord, $name = 'Word2007', $config = []) : WriterInterface { if ($name !== 'WriterInterface' && !in_array($name, ['ODText', 'RTF', 'Word2007', 'HTML', 'PDF'], true)) { throw new Exception("\"{$name}\" is not a valid writer."); diff --git a/src/PhpWord/Writer/AbstractWriter.php b/src/PhpWord/Writer/AbstractWriter.php index dc7f09de0f..0aee619707 100644 --- a/src/PhpWord/Writer/AbstractWriter.php +++ b/src/PhpWord/Writer/AbstractWriter.php @@ -100,6 +100,12 @@ abstract class AbstractWriter implements WriterInterface */ protected $config; + /** + * construct method. + * + * @param PhpWord|null $phpWord + * @param array $config + */ public function __construct(?PhpWord $phpWord = null, $config = []) { $this->setPhpWord($phpWord); diff --git a/src/PhpWord/Writer/PDF/AbstractRenderer.php b/src/PhpWord/Writer/PDF/AbstractRenderer.php index 8b777b69fd..b07aebb142 100644 --- a/src/PhpWord/Writer/PDF/AbstractRenderer.php +++ b/src/PhpWord/Writer/PDF/AbstractRenderer.php @@ -73,23 +73,17 @@ abstract class AbstractRenderer extends HTML 9 => 'A4', // (210 mm by 297 mm) ]; - /** - * config in MPDF. - * - * @var array|mixed - */ - protected $config; - /** * Create new instance. * - * @param PhpWord $phpWord PhpWord object + * @param PhpWord $phpWord * @param array $config */ public function __construct(PhpWord $phpWord, $config = []) { - parent::__construct($phpWord); - $this->config = $config; + // Assign PhpWord + parent::__construct($phpWord, $config); + $this->isPdf = true; if ($this->includeFile != null) { $includeFile = Settings::getPdfRendererPath() . '/' . $this->includeFile; From a37909857f9b30ad72624fe075b9c7735f27bd61 Mon Sep 17 00:00:00 2001 From: boshi_no_1 Date: Fri, 24 May 2024 13:48:33 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E4=B8=BAPHPWord=E7=9A=84MPDF=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=B7=BB=E5=8A=A0config=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E5=85=B6=E5=8F=AF=E4=BB=A5=E6=AD=A3=E5=B8=B8=E8=A2=AB?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/IOFactory.php | 4 +--- src/PhpWord/Writer/AbstractWriter.php | 1 - src/PhpWord/Writer/PDF/AbstractRenderer.php | 1 - src/PhpWord/Writer/Word2007.php | 2 +- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/PhpWord/IOFactory.php b/src/PhpWord/IOFactory.php index 4f84cbb33b..c232ce8fb4 100644 --- a/src/PhpWord/IOFactory.php +++ b/src/PhpWord/IOFactory.php @@ -31,10 +31,8 @@ abstract class IOFactory * * @param string $name * @param array $config - * - * @return WriterInterface */ - public static function createWriter(PhpWord $phpWord, $name = 'Word2007', $config = []) : WriterInterface + public static function createWriter(PhpWord $phpWord, $name = 'Word2007', $config = []): WriterInterface { if ($name !== 'WriterInterface' && !in_array($name, ['ODText', 'RTF', 'Word2007', 'HTML', 'PDF'], true)) { throw new Exception("\"{$name}\" is not a valid writer."); diff --git a/src/PhpWord/Writer/AbstractWriter.php b/src/PhpWord/Writer/AbstractWriter.php index 0aee619707..d5f30b4a17 100644 --- a/src/PhpWord/Writer/AbstractWriter.php +++ b/src/PhpWord/Writer/AbstractWriter.php @@ -103,7 +103,6 @@ abstract class AbstractWriter implements WriterInterface /** * construct method. * - * @param PhpWord|null $phpWord * @param array $config */ public function __construct(?PhpWord $phpWord = null, $config = []) diff --git a/src/PhpWord/Writer/PDF/AbstractRenderer.php b/src/PhpWord/Writer/PDF/AbstractRenderer.php index b07aebb142..534372cd37 100644 --- a/src/PhpWord/Writer/PDF/AbstractRenderer.php +++ b/src/PhpWord/Writer/PDF/AbstractRenderer.php @@ -76,7 +76,6 @@ abstract class AbstractRenderer extends HTML /** * Create new instance. * - * @param PhpWord $phpWord * @param array $config */ public function __construct(PhpWord $phpWord, $config = []) diff --git a/src/PhpWord/Writer/Word2007.php b/src/PhpWord/Writer/Word2007.php index 32c58d0d30..9e1d308871 100644 --- a/src/PhpWord/Writer/Word2007.php +++ b/src/PhpWord/Writer/Word2007.php @@ -79,7 +79,7 @@ public function __construct(?PhpWord $phpWord = null, $config = []) foreach (array_keys($this->parts) as $partName) { $partClass = static::class . '\\Part\\' . $partName; if (class_exists($partClass)) { - /** @var \PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart $part Type hint */ + /** @var \PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart $part */ $part = new $partClass(); $part->setParentWriter($this); $this->writerParts[strtolower($partName)] = $part;