From f28ac29c413280dc455dadca2d3a6da44b608a47 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 24 Feb 2015 17:37:07 -0800 Subject: [PATCH] CRM-16005 - Use and configure the dompdf provided by composer. --- CRM/Utils/PDF/Utils.php | 6 +- composer.json | 9 ++ tools/scripts/composer/dompdf-cleanup.sh | 121 +++++++++++++++++++++++ 3 files changed, 133 insertions(+), 3 deletions(-) create mode 100755 tools/scripts/composer/dompdf-cleanup.sh diff --git a/CRM/Utils/PDF/Utils.php b/CRM/Utils/PDF/Utils.php index 90f36cecdf..f7dc760449 100644 --- a/CRM/Utils/PDF/Utils.php +++ b/CRM/Utils/PDF/Utils.php @@ -191,9 +191,9 @@ class CRM_Utils_PDF_Utils { */ public static function _html2pdf_dompdf($paper_size, $orientation, $html, $output, $fileName) { // CRM-12165 - Remote file support required for image handling. - define("DOMPDF_ENABLE_REMOTE", true); - define('DOMPDF_ENABLE_AUTOLOAD', false); - require_once 'packages/vendor/dompdf/dompdf/dompdf_config.inc.php'; + define('DOMPDF_ENABLE_REMOTE', TRUE); + define('DOMPDF_ENABLE_AUTOLOAD', FALSE); + require_once 'vendor/dompdf/dompdf/dompdf_config.inc.php'; $dompdf = new DOMPDF(); $dompdf->set_paper($paper_size, $orientation); diff --git a/composer.json b/composer.json index 89325b9843..d4701c874b 100644 --- a/composer.json +++ b/composer.json @@ -6,10 +6,19 @@ } }, "require": { + "dompdf/dompdf" : "0.6.*", "symfony/dependency-injection": "2.3.*", "symfony/event-dispatcher": "2.3.*", "psr/log": "1.0.0", "symfony/finder": "2.3.*", "totten/ca-config": "~13.02" + }, + "scripts": { + "post-install-cmd": [ + "bash tools/scripts/composer/dompdf-cleanup.sh" + ], + "post-update-cmd": [ + "bash tools/scripts/composer/dompdf-cleanup.sh" + ] } } diff --git a/tools/scripts/composer/dompdf-cleanup.sh b/tools/scripts/composer/dompdf-cleanup.sh new file mode 100755 index 0000000000..b17e50d5bd --- /dev/null +++ b/tools/scripts/composer/dompdf-cleanup.sh @@ -0,0 +1,121 @@ +#!/bin/bash + +## Cleanup the vendor tree. The main issue here is that civi Civi is +## deployed as a module inside a CMS, so all its source-code gets published. +## Some libraries distribute admin tools and sample files which should not +## be published. +## +## This script should be idempotent -- if you rerun it several times, it +## should always produce the same post-condition. + +############################################################################## +## usage: safe_delete +function safe_delete() { + for file in "$@" ; do + if [ -z "$file" ]; then + echo "Skip: empty file name" + elif [ -e "$file" ]; then + rm -rf "$file" + fi + done +} + +############################################################################## +## usage: make_font_cache > font-cache.php +function make_font_cache() { +cat < + array ( + 'normal' => DOMPDF_DIR . '/lib/fonts/Helvetica', + 'bold' => DOMPDF_DIR . '/lib/fonts/Helvetica-Bold', + 'italic' => DOMPDF_DIR . '/lib/fonts/Helvetica-Oblique', + 'bold_italic' => DOMPDF_DIR . '/lib/fonts/Helvetica-BoldOblique', + ), + 'times' => + array ( + 'normal' => DOMPDF_DIR . '/lib/fonts/Times-Roman', + 'bold' => DOMPDF_DIR . '/lib/fonts/Times-Bold', + 'italic' => DOMPDF_DIR . '/lib/fonts/Times-Italic', + 'bold_italic' => DOMPDF_DIR . '/lib/fonts/Times-BoldItalic', + ), + 'times-roman' => + array ( + 'normal' => DOMPDF_DIR . '/lib/fonts/Times-Roman', + 'bold' => DOMPDF_DIR . '/lib/fonts/Times-Bold', + 'italic' => DOMPDF_DIR . '/lib/fonts/Times-Italic', + 'bold_italic' => DOMPDF_DIR . '/lib/fonts/Times-BoldItalic', + ), + 'courier' => + array ( + 'normal' => DOMPDF_DIR . '/lib/fonts/Courier', + 'bold' => DOMPDF_DIR . '/lib/fonts/Courier-Bold', + 'italic' => DOMPDF_DIR . '/lib/fonts/Courier-Oblique', + 'bold_italic' => DOMPDF_DIR . '/lib/fonts/Courier-BoldOblique', + ), + 'helvetica' => + array ( + 'normal' => DOMPDF_DIR . '/lib/fonts/Helvetica', + 'bold' => DOMPDF_DIR . '/lib/fonts/Helvetica-Bold', + 'italic' => DOMPDF_DIR . '/lib/fonts/Helvetica-Oblique', + 'bold_italic' => DOMPDF_DIR . '/lib/fonts/Helvetica-BoldOblique', + ), + 'zapfdingbats' => + array ( + 'normal' => DOMPDF_DIR . '/lib/fonts/ZapfDingbats', + 'bold' => DOMPDF_DIR . '/lib/fonts/ZapfDingbats', + 'italic' => DOMPDF_DIR . '/lib/fonts/ZapfDingbats', + 'bold_italic' => DOMPDF_DIR . '/lib/fonts/ZapfDingbats', + ), + 'symbol' => + array ( + 'normal' => DOMPDF_DIR . '/lib/fonts/Symbol', + 'bold' => DOMPDF_DIR . '/lib/fonts/Symbol', + 'italic' => DOMPDF_DIR . '/lib/fonts/Symbol', + 'bold_italic' => DOMPDF_DIR . '/lib/fonts/Symbol', + ), + 'serif' => + array ( + 'normal' => DOMPDF_DIR . '/lib/fonts/Times-Roman', + 'bold' => DOMPDF_DIR . '/lib/fonts/Times-Bold', + 'italic' => DOMPDF_DIR . '/lib/fonts/Times-Italic', + 'bold_italic' => DOMPDF_DIR . '/lib/fonts/Times-BoldItalic', + ), + 'monospace' => + array ( + 'normal' => DOMPDF_DIR . '/lib/fonts/Courier', + 'bold' => DOMPDF_DIR . '/lib/fonts/Courier-Bold', + 'italic' => DOMPDF_DIR . '/lib/fonts/Courier-Oblique', + 'bold_italic' => DOMPDF_DIR . '/lib/fonts/Courier-BoldOblique', + ), + 'fixed' => + array ( + 'normal' => DOMPDF_DIR . '/lib/fonts/Courier', + 'bold' => DOMPDF_DIR . '/lib/fonts/Courier-Bold', + 'italic' => DOMPDF_DIR . '/lib/fonts/Courier-Oblique', + 'bold_italic' => DOMPDF_DIR . '/lib/fonts/Courier-BoldOblique', + ), +) ?> +EOFONT +} + +function make_font_readme() { +cat < vendor/dompdf/dompdf/lib/fonts/dompdf_font_family_cache.dist.php +make_font_readme > vendor/dompdf/dompdf/lib/fonts/README.DejaVuFonts.txt -- 2.25.1