Skip to content

Commit

Permalink
Merge pull request #1 from rarog/master
Browse files Browse the repository at this point in the history
Changing to Dompdf 0.7.0
  • Loading branch information
Mike Zukowsky authored Aug 2, 2016
2 parents 5bf59f8 + a9526f0 commit 28f6fb4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 82 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"homepage": "http://www.phpcontext.com",
"require": {
"php": ">=5.3.0",
"dompdf/dompdf": "~0.6"
"dompdf/dompdf": "~0.7.0"
},
"autoload": {
"psr-0": {
Expand Down
51 changes: 20 additions & 31 deletions config/dompdf.config.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,24 @@
$dompdfDir = realpath('vendor/dompdf/dompdf');

return array(
'DOMPDF_DIR' => $dompdfDir,
'DOMPDF_TEMP_DIR' => sys_get_temp_dir(),
'DOMPDF_FONT_DIR' => $dompdfDir . '/lib/fonts',
'DOMPDF_FONT_CACHE' => $dompdfDir . '/lib/fonts',
'DOMPDF_INC_DIR' => $dompdfDir . '/include',
'DOMPDF_LIB_DIR' => $dompdfDir . '/lib',
'DOMPDF_CHROOT' => '',
'DOMPDF_LOG_OUTPUT_FILE' => false,
'DOMPDF_DEFAULT_MEDIA_TYPE' => 'screen',
'DOMPDF_DEFAULT_PAPER_SIZE' => 'A4',
'DOMPDF_DEFAULT_FONT' => 'serif',
'DOMPDF_DPI' => 96,
'DOMPDF_PDF_BACKEND' => 'CPDF',
'DOMPDF_FONT_HEIGHT_RATIO' => 1.1,
'DOMPDF_UNICODE_ENABLED' => true,
'DOMPDF_ENABLE_PHP' => false,
'DOMPDF_ENABLE_REMOTE' => false,
'DOMPDF_ENABLE_CSS_FLOAT' => true,
'DOMPDF_ENABLE_JAVASCRIPT' => false,
'DOMPDF_ENABLE_HTML5PARSER' => true,
'DOMPDF_ENABLE_FONTSUBSETTING' => false,
'DEBUGPNG' => false,
'DEBUGKEEPTEMP' => false,
'DEBUGCSS' => false,
'DEBUG_LAYOUT' => false,
'DEBUG_LAYOUT_LINES' => false,
'DEBUG_LAYOUT_BLOCKS' => false,
'DEBUG_LAYOUT_INLINE' => false,
'DEBUG_LAYOUT_PADDINGBOX' => false,
'DOMPDF_ADMIN_USERNAME' => 'admin',
'DOMPDF_ADMIN_PASSWORD' => 'p4$$w0rd',
'logOutputFile' => false,
'defaultMediaType' => 'screen',
'defaultPaperSize' => 'A4',
'defaultFont' => 'serif',
'dpi' => 96,
'pdfBackend' => 'CPDF',
'fontHeightRatio' => 1.1,
'isPhpEnabled' => false,
'isRemoteEnabled' => false,
'isJavascriptEnabled' => false,
'isHtml5ParserEnabled' => true,
'isFontSubsettingEnabled' => false,
'debugPng' => false,
'debugKeepTemp' => false,
'debugCss' => false,
'debugLayout' => false,
'debugLayoutLines' => false,
'debugLayoutBlocks' => false,
'debugLayoutInline' => false,
'debugLayoutPaddingBox' => false,
);
80 changes: 30 additions & 50 deletions src/dompdfmodule/Service/dompdfFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,40 @@

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use DOMPDF;
use Dompdf\Dompdf;
use Dompdf\Options;

class dompdfFactory implements FactoryInterface
{
/**
* @param ServiceLocatorInterface $serviceLocator
* @return DOMPDF
* @return Dompdf
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
if (defined('DOMPDF_DIR')) {
// return object early if already initialized
return new DOMPDF();
}

// load user config
$config = $serviceLocator->get('config');
$userConfig = isset($config['dompdf']) ? $config['dompdf'] : array();

// evaluate library directory
$dompdfDir = isset($userConfig['DOMPDF_DIR']) ?
$userConfig['DOMPDF_DIR'] :
realpath('vendor/dompdf/dompdf');

// merge default config with user config if necessary
$dompdfConfig = count($userConfig) ?
array_merge($this->createDefaultSettings($dompdfDir), $userConfig) :
$this->createDefaultSettings($dompdfDir);

// register constants

// set options
$options = new Options();
foreach ($dompdfConfig as $settingName => $settingValue) {
if (! defined($settingName)) {
define($settingName, $settingValue);
$options->set($settingName, $settingValue);
}
}

// finally load required files and create the object
require_once DOMPDF_LIB_DIR . '/html5lib/Parser.php';
require_once DOMPDF_INC_DIR . '/functions.inc.php';

return new DOMPDF();
return new Dompdf($options);
}

/**
Expand All @@ -54,40 +47,27 @@ public function createService(ServiceLocatorInterface $serviceLocator)
protected function createDefaultSettings($dompdfDir)
{
return array(
'DOMPDF_DIR' => $dompdfDir,
'DOMPDF_TEMP_DIR' => sys_get_temp_dir(),
'DOMPDF_FONT_DIR' => $dompdfDir . '/lib/fonts',
'DOMPDF_FONT_CACHE' => $dompdfDir . '/lib/fonts',
'DOMPDF_INC_DIR' => $dompdfDir . '/include',
'DOMPDF_LIB_DIR' => $dompdfDir . '/lib',

'DOMPDF_CHROOT' => '',
'DOMPDF_LOG_OUTPUT_FILE' => false,
'DOMPDF_DEFAULT_MEDIA_TYPE' => 'screen',
'DOMPDF_DEFAULT_PAPER_SIZE' => 'A4',
'DOMPDF_DEFAULT_FONT' => 'serif',
'DOMPDF_DPI' => 96,
'DOMPDF_PDF_BACKEND' => 'CPDF',
'DOMPDF_FONT_HEIGHT_RATIO' => 1.1,
'DOMPDF_UNICODE_ENABLED' => true,
'DOMPDF_ENABLE_PHP' => false,
'DOMPDF_ENABLE_REMOTE' => false,
'DOMPDF_ENABLE_CSS_FLOAT' => true,
'DOMPDF_ENABLE_JAVASCRIPT' => false,
'DOMPDF_ENABLE_HTML5PARSER' => true,
'DOMPDF_ENABLE_FONTSUBSETTING' => false,

'DEBUGPNG' => false,
'DEBUGKEEPTEMP' => false,
'DEBUGCSS' => false,
'DEBUG_LAYOUT' => false,
'DEBUG_LAYOUT_LINES' => false,
'DEBUG_LAYOUT_BLOCKS' => false,
'DEBUG_LAYOUT_INLINE' => false,
'DEBUG_LAYOUT_PADDINGBOX' => false,
'logOutputFile' => false,
'defaultMediaType' => 'screen',
'defaultPaperSize' => 'A4',
'defaultFont' => 'serif',
'dpi' => 96,
'pdfBackend' => 'CPDF',
'fontHeightRatio' => 1.1,
'isPhpEnabled' => false,
'isRemoteEnabled' => false,
'isJavascriptEnabled' => false,
'isHtml5ParserEnabled' => true,
'isFontSubsettingEnabled' => false,

'DOMPDF_ADMIN_USERNAME' => 'admin',
'DOMPDF_ADMIN_PASSWORD' => 'p4$$w0rd',
'debugPng' => false,
'debugKeepTemp' => false,
'debugCss' => false,
'debugLayout' => false,
'debugLayoutLines' => false,
'debugLayoutBlocks' => false,
'debugLayoutInline' => false,
'debugLayoutPaddingBox' => false,
);
}
}

0 comments on commit 28f6fb4

Please sign in to comment.