Open NoVizin opened 7 years ago
@NoVizin You can try this: http://stackoverflow.com/questions/25563870/making-dompdf-as-my-pdf-writer-for-phpword
Dompdf has not included dompdf_config.inc.php
since 0.7.0 and it also nowadays places classes in a namespace. Until PHPWord is updated, the following work-around worked for me.
<?php
// To enable pdf exporting with phpword
class_alias( \Dompdf\Dompdf::class, 'DOMPDF' );
// Assuming dompdf_config.inc.php is in the same directory
use \PhpOffice\PhpWord\Settings;
Settings::setPdfRenderer( Settings::PDF_RENDERER_DOMPDF, __DIR__ );
The info from @Nikerabbit worked from me. However, one small edit needs to be made to dompdf_config.inc.php there needs to be a semi-colon placed at the end of the class_alias() line.
If I put the dompdf_config.inc.php in the samples dir, then modify Sample_Header.php and place the Settings:: line under the already existing use line in there, then it works, I can produce a PDF.
However, the PDF version loses a lot of formatting, but I suppose that's another issue altogether. I've tried dompdf versions 0.8.0, 0.7.0, and 0.6.2.
I updated my comment to include the semi-colon, for any future copy-pasters ;)
Sorry @JoeThielen and @Nikerabbit just one request. Where i need to create dompdf_config.inc.php?
@GHim9182 I put it in the same directory as the project I was working on. In my case, it was the samples directory of PHPWord, since that is what I was testing.
PhpWord library is working fine, but not Dompdf!
index.php
<php require 'vendor/autoload.php'; $phpWord = new \PhpOffice\PhpWord\PhpWord(); $dompdf = new Dompdf(); .... .... ?>
composer.json code
{ "require": { "phpoffice/phpword": "v0.13.*", "dompdf/dompdf": "^0.7.0" } }
composer.lock
{ "_readme": [ "This file locks the dependencies of your project to a known state", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], "content-hash": "b5057605bc20d2d2da19cce1cacfeefc", "packages": [ { "name": "dompdf/dompdf", "version": "v0.7.0", "source": { "type": "git", "url": "https://github.com/dompdf/dompdf.git", "reference": "5c98652b1a5beb7e3cc8ec35419b2828dd63ab14" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/dompdf/dompdf/zipball/5c98652b1a5beb7e3cc8ec35419b2828dd63ab14", "reference": "5c98652b1a5beb7e3cc8ec35419b2828dd63ab14", "shasum": "" }, "require": { "ext-dom": "", "ext-gd": "", "ext-mbstring": "", "phenx/php-font-lib": "0.4.", "phenx/php-svg-lib": "0.1.", "php": ">=5.3.0" }, "require-dev": { "phpunit/phpunit": "3.7." }, "type": "library", "extra": { "branch-alias": { "dev-develop": "0.7-dev" } }, "autoload": { "psr-4": { "Dompdf\": "src/" }, "classmap": [ "lib/" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "LGPL-2.1" ], "authors": [ { "name": "Fabien Ménager", "email": "fabien.menager@gmail.com" }, { "name": "Brian Sweeney", "email": "eclecticgeek@gmail.com" }, { "name": "Gabriel Bull", "email": "me@gabrielbull.com" } ], "description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter", "homepage": "https://github.com/dompdf/dompdf", "time": "2016-05-11T00:36:29+00:00" }, { "name": "pclzip/pclzip", "version": "2.8.2", "source": { "type": "git", "url": "https://github.com/ivanlanin/pclzip.git", "reference": "19dd1de9d3f5fc4d7d70175b4c344dee329f45fd" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/ivanlanin/pclzip/zipball/19dd1de9d3f5fc4d7d70175b4c344dee329f45fd", "reference": "19dd1de9d3f5fc4d7d70175b4c344dee329f45fd", "shasum": "" }, "type": "library", "autoload": { "classmap": [ "pclzip.lib.php" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "LGPL-2.1" ], "authors": [ { "name": "Vincent Blavet" } ], "description": "A PHP library that offers compression and extraction functions for Zip formatted archives", "homepage": "http://www.phpconcept.net/pclzip", "keywords": [ "php", "zip" ], "time": "2014-06-05T11:42:24+00:00" }, { "name": "phenx/php-font-lib", "version": "0.4", "source": { "type": "git", "url": "https://github.com/PhenX/php-font-lib.git", "reference": "b8af0cacdc3cbf1e41a586fcb78f506f4121a088" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/PhenX/php-font-lib/zipball/b8af0cacdc3cbf1e41a586fcb78f506f4121a088", "reference": "b8af0cacdc3cbf1e41a586fcb78f506f4121a088", "shasum": "" }, "type": "library", "autoload": { "psr-0": { "FontLib\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "LGPL-3.0" ], "authors": [ { "name": "Fabien Ménager", "email": "fabien.menager@gmail.com" } ], "description": "A library to read, parse, export and make subsets of different types of font files.", "homepage": "https://github.com/PhenX/php-font-lib", "time": "2015-05-06T20:02:39+00:00" }, { "name": "phenx/php-svg-lib", "version": "0.1", "source": { "type": "git", "url": "https://github.com/PhenX/php-svg-lib.git", "reference": "b419766515b3426c6da74b0e29e93d71c4f17099" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/PhenX/php-svg-lib/zipball/b419766515b3426c6da74b0e29e93d71c4f17099", "reference": "b419766515b3426c6da74b0e29e93d71c4f17099", "shasum": "" }, "type": "library", "autoload": { "psr-0": { "Svg\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "LGPL-3.0" ], "authors": [ { "name": "Fabien Ménager", "email": "fabien.menager@gmail.com" } ], "description": "A library to read, parse and export to PDF SVG files.", "homepage": "https://github.com/PhenX/php-svg-lib", "time": "2015-05-06T18:49:49+00:00" }, { "name": "phpoffice/common", "version": "v0.2.6", "source": { "type": "git", "url": "https://github.com/PHPOffice/Common.git", "reference": "c9be70c80637c28c728be78e66aad4878a34f8dd" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/PHPOffice/Common/zipball/c9be70c80637c28c728be78e66aad4878a34f8dd", "reference": "c9be70c80637c28c728be78e66aad4878a34f8dd", "shasum": "" }, "require": { "pclzip/pclzip": "^2.8", "php": ">=5.3.0" }, "require-dev": { "phpdocumentor/phpdocumentor": "2.", "phploc/phploc": "2.", "phpmd/phpmd": "2.", "phpunit/phpunit": "3.7.", "sebastian/phpcpd": "2.", "squizlabs/php_codesniffer": "2." }, "type": "library", "autoload": { "psr-4": { "PhpOffice\Common\": "src/Common/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "LGPL" ], "authors": [ { "name": "Mark Baker" }, { "name": "Franck Lefevre", "homepage": "http://rootslabs.net" } ], "description": "PHPOffice Common", "homepage": "http://phpoffice.github.io", "keywords": [ "common", "component", "office", "php" ], "time": "2016-07-07T17:26:55+00:00" }, { "name": "phpoffice/phpword", "version": "v0.13.0", "source": { "type": "git", "url": "https://github.com/PHPOffice/PHPWord.git", "reference": "0a3f873972defb304de4fa2f5f53156558c11a7a" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/PHPOffice/PHPWord/zipball/0a3f873972defb304de4fa2f5f53156558c11a7a", "reference": "0a3f873972defb304de4fa2f5f53156558c11a7a", "shasum": "" }, "require": { "ext-xml": "", "php": ">=5.3.3", "phpoffice/common": "0.2.", "zendframework/zend-escaper": "2.4.", "zendframework/zend-stdlib": "2.4.", "zendframework/zend-validator": "2.4." }, "require-dev": { "dompdf/dompdf": "0.6.", "mpdf/mpdf": "5.", "phpdocumentor/phpdocumentor": "2.", "phploc/phploc": "2.", "phpmd/phpmd": "2.", "phpunit/phpunit": "3.7.", "squizlabs/php_codesniffer": "1.", "tecnickcom/tcpdf": "6." }, "suggest": { "dompdf/dompdf": "Allows writing PDF", "ext-gd2": "Allows adding images", "ext-xmlwriter": "Allows writing OOXML and ODF", "ext-xsl": "Allows applying XSL style sheet to headers, to main document part, and to footers of an OOXML template", "ext-zip": "Allows writing OOXML and ODF" }, "type": "library", "autoload": { "psr-4": { "PhpOffice\PhpWord\": "src/PhpWord" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "LGPL-3.0" ], "authors": [ { "name": "Mark Baker" }, { "name": "Franck Lefevre", "homepage": "http://blog.rootslabs.net" }, { "name": "Gabriel Bull", "email": "me@gabrielbull.com", "homepage": "http://gabrielbull.com/" }, { "name": "Ivan Lanin", "homepage": "http://ivan.lanin.org" }, { "name": "Roman Syroeshko", "homepage": "http://ru.linkedin.com/pub/roman-syroeshko/34/a53/994/" } ], "description": "PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)", "homepage": "http://phpoffice.github.io", "keywords": [ "ISO IEC 29500", "OOXML", "Office Open XML", "OpenDocument", "OpenXML", "PhpOffice", "PhpWord", "Rich Text Format", "WordprocessingML", "doc", "docx", "html", "odf", "odt", "office", "pdf", "php", "reader", "rtf", "template", "template processor", "word", "writer" ], "time": "2016-07-31T08:53:39+00:00" }, { "name": "zendframework/zend-escaper", "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-escaper.git", "reference": "13f468ff824f3c83018b90aff892a1b3201383a9" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/zendframework/zend-escaper/zipball/13f468ff824f3c83018b90aff892a1b3201383a9", "reference": "13f468ff824f3c83018b90aff892a1b3201383a9", "shasum": "" }, "require": { "php": ">=5.3.23" }, "require-dev": { "fabpot/php-cs-fixer": "1.7.", "phpunit/phpunit": "~4.0", "satooshi/php-coveralls": "dev-master" }, "type": "library", "extra": { "branch-alias": { "dev-master": "2.4-dev", "dev-develop": "2.5-dev" } }, "autoload": { "psr-4": { "Zend\Escaper\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" ], "homepage": "https://github.com/zendframework/zend-escaper", "keywords": [ "escaper", "zf2" ], "time": "2015-05-07T14:55:31+00:00" }, { "name": "zendframework/zend-stdlib", "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-stdlib.git", "reference": "d8ecb629a72da9f91bd95c5af006384823560b42" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/zendframework/zend-stdlib/zipball/d8ecb629a72da9f91bd95c5af006384823560b42", "reference": "d8ecb629a72da9f91bd95c5af006384823560b42", "shasum": "" }, "require": { "php": ">=5.3.23" }, "require-dev": { "fabpot/php-cs-fixer": "1.7.", "phpunit/phpunit": "~4.0", "satooshi/php-coveralls": "dev-master", "zendframework/zend-eventmanager": "self.version", "zendframework/zend-filter": "self.version", "zendframework/zend-serializer": "self.version", "zendframework/zend-servicemanager": "self.version" }, "suggest": { "zendframework/zend-eventmanager": "To support aggregate hydrator usage", "zendframework/zend-filter": "To support naming strategy hydrator usage", "zendframework/zend-serializer": "Zend\Serializer component", "zendframework/zend-servicemanager": "To support hydrator plugin manager usage" }, "type": "library", "extra": { "branch-alias": { "dev-master": "2.4-dev", "dev-develop": "2.5-dev" } }, "autoload": { "psr-4": { "Zend\Stdlib\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" ], "homepage": "https://github.com/zendframework/zend-stdlib", "keywords": [ "stdlib", "zf2" ], "time": "2015-07-21T13:55:46+00:00" }, { "name": "zendframework/zend-validator", "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-validator.git", "reference": "81415511fe729e6de19a61936313cef43c80d337" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/zendframework/zend-validator/zipball/81415511fe729e6de19a61936313cef43c80d337", "reference": "81415511fe729e6de19a61936313cef43c80d337", "shasum": "" }, "require": { "php": ">=5.3.23", "zendframework/zend-stdlib": "~2.4.0" }, "require-dev": { "fabpot/php-cs-fixer": "1.7.", "phpunit/phpunit": "~4.0", "satooshi/php-coveralls": "dev-master", "zendframework/zend-config": "~2.4.0", "zendframework/zend-db": "~2.4.0", "zendframework/zend-filter": "~2.4.0", "zendframework/zend-i18n": "~2.4.0", "zendframework/zend-math": "~2.4.0", "zendframework/zend-servicemanager": "~2.4.0", "zendframework/zend-session": "~2.4.0", "zendframework/zend-uri": "~2.4.0" }, "suggest": { "zendframework/zend-db": "Zend\Db component", "zendframework/zend-filter": "Zend\Filter component, required by the Digits validator", "zendframework/zend-i18n": "Zend\I18n component to allow translation of validation error messages as well as to use the various Date validators", "zendframework/zend-math": "Zend\Math component", "zendframework/zend-resources": "Translations of validator messages", "zendframework/zend-servicemanager": "Zend\ServiceManager component to allow using the ValidatorPluginManager and validator chains", "zendframework/zend-session": "Zend\Session component", "zendframework/zend-uri": "Zend\Uri component, required by the Uri and Sitemap\Loc validators" }, "type": "library", "extra": { "branch-alias": { "dev-master": "2.4-dev", "dev-develop": "2.5-dev" } }, "autoload": { "psr-4": { "Zend\Validator\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" ], "description": "provides a set of commonly needed validators", "homepage": "https://github.com/zendframework/zend-validator", "keywords": [ "validator", "zf2" ], "time": "2015-09-08T21:04:17+00:00" } ], "packages-dev": [], "aliases": [], "minimum-stability": "stable", "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": [], "platform-dev": [] }