diff --git a/src/PhpWord/IOFactory.php b/src/PhpWord/IOFactory.php index de2656d8c6..5ff0be19f2 100644 --- a/src/PhpWord/IOFactory.php +++ b/src/PhpWord/IOFactory.php @@ -28,10 +28,11 @@ abstract class IOFactory * Create new writer. * * @param string $name + * @param array $config * * @return WriterInterface */ - public static function createWriter(PhpWord $phpWord, $name = 'Word2007') + public static function createWriter(PhpWord $phpWord, $name = 'Word2007', $config = array()) { if ($name !== 'WriterInterface' && !in_array($name, ['ODText', 'RTF', 'Word2007', 'HTML', 'PDF'], true)) { throw new Exception("\"{$name}\" is not a valid writer."); @@ -39,7 +40,7 @@ public static function createWriter(PhpWord $phpWord, $name = 'Word2007') $fqName = "PhpOffice\\PhpWord\\Writer\\{$name}"; - return new $fqName($phpWord); + return ($name == 'PDF' && !empty($config)) ? new $fqName($phpWord, $config) : new $fqName($phpWord); } /** diff --git a/src/PhpWord/Writer/PDF/AbstractRenderer.php b/src/PhpWord/Writer/PDF/AbstractRenderer.php index e8be7c06a5..a09039efd0 100644 --- a/src/PhpWord/Writer/PDF/AbstractRenderer.php +++ b/src/PhpWord/Writer/PDF/AbstractRenderer.php @@ -77,8 +77,12 @@ abstract class AbstractRenderer extends HTML * Create new instance. * * @param PhpWord $phpWord PhpWord object + * + * @param array $config + * + * @throws \PhpOffice\PhpWord\Exception\Exception */ - public function __construct(PhpWord $phpWord) + public function __construct(PhpWord $phpWord, $config = array()) { parent::__construct($phpWord); if ($this->includeFile != null) { @@ -93,6 +97,7 @@ public function __construct(PhpWord $phpWord) // @codeCoverageIgnoreEnd } } + if(isset($config['font']) && empty($config['font'])) $this->font = $config['font']; } /** diff --git a/src/PhpWord/Writer/PDF/DomPDF.php b/src/PhpWord/Writer/PDF/DomPDF.php index 26ceb79b55..812cb12e9a 100644 --- a/src/PhpWord/Writer/PDF/DomPDF.php +++ b/src/PhpWord/Writer/PDF/DomPDF.php @@ -18,6 +18,7 @@ namespace PhpOffice\PhpWord\Writer\PDF; use Dompdf\Dompdf as DompdfLib; +use Dompdf\Options; use PhpOffice\PhpWord\Writer\WriterInterface; /** @@ -42,7 +43,15 @@ class DomPDF extends AbstractRenderer implements WriterInterface */ protected function createExternalWriterInstance() { - return new DompdfLib(); + if(!empty($this->font)){ + $options = new Options(); + $options->set('defaultFont', $this->font); + $instance = new DompdfLib($options); + }else{ + $instance = new DompdfLib(); + } + + return $instance; } /**