diff --git a/composer.json b/composer.json index 5bae0a4943e..6c0442e2587 100755 --- a/composer.json +++ b/composer.json @@ -80,7 +80,7 @@ "media-alchemyst/media-alchemyst": "~0.5", "michelf/php-markdown": "~1.7", "monolog/monolog": "~1.0", - "mpdf/mpdf": "6.1.*", + "mpdf/mpdf": "^8.0", "ocramius/proxy-manager": "~1.0|2.0.*", "onelogin/php-saml": "^3.0", "packbackbooks/lti-1p3-tool": "^1.1", diff --git a/main/inc/lib/pdf.lib.php b/main/inc/lib/pdf.lib.php index cfee2e2876f..9a102ac6a4e 100755 --- a/main/inc/lib/pdf.lib.php +++ b/main/inc/lib/pdf.lib.php @@ -2,13 +2,16 @@ /* See license terms in /license.txt */ use Chamilo\CoreBundle\Component\Utils\ChamiloApi; +use Mpdf\Mpdf; +use Mpdf\MpdfException; +use Mpdf\Utils\UtfString; /** * Class PDF. */ class PDF { - /** @var mPDF */ + /** @var Mpdf */ public $pdf; public $custom_header = []; public $custom_footer = []; @@ -16,13 +19,15 @@ class PDF public $template; /** - * Creates the mPDF object. + * Creates the Mpdf object. * * @param string $pageFormat format A4 A4-L see * http://mpdf1.com/manual/index.php?tid=184&searchstring=format * @param string $orientation orientation "P" = Portrait "L" = Landscape * @param array $params * @param Template $template + * + * @throws MpdfException */ public function __construct( $pageFormat = 'A4', @@ -31,7 +36,7 @@ public function __construct( $template = null ) { $this->template = $template; - /* More info @ http://mpdf1.com/manual/index.php?tid=184&searchstring=mPDF */ + /* More info @ http://mpdf1.com/manual/index.php?tid=184&searchstring=Mpdf */ if (!in_array($orientation, ['P', 'L'])) { $orientation = 'P'; } @@ -58,18 +63,21 @@ public function __construct( $this->params['pdf_date'] = isset($params['pdf_date']) ? $params['pdf_date'] : api_format_date($localTime, DATE_TIME_FORMAT_LONG); $this->params['pdf_date_only'] = isset($params['pdf_date']) ? $params['pdf_date'] : api_format_date($localTime, DATE_FORMAT_LONG); - @$this->pdf = new mPDF( - 'UTF-8', - $pageFormat, - '', - '', - $params['left'], - $params['right'], - $params['top'], - $params['bottom'], - 8, - 8, - $orientation + $this->pdf = new Mpdf( + [ + 'mode' => 'UTF-8', + 'format' => $pageFormat, + 'default_font_size' => '', + 'default_font' => '', + 'margin_left' => $params['left'], + 'margin_right' => $params['right'], + 'margin_top' => $params['top'], + 'margin_bottom' => $params['bottom'], + 'margin_header' => 8, + 'margin_footer' => 8, + 'orientation' => $orientation, + 'tempDir' => api_get_path(SYS_ARCHIVE_PATH).'mpdf/', + ] ); $this->pdf->margin_footer = $params['margin_footer']; @@ -92,7 +100,9 @@ public function __construct( * @param bool $addDefaultCss (bootstrap/default/base.css) * @param array * - * @return string + * @throws MpdfException + * + * @return string|null */ public function html_to_pdf_with_template( $content, @@ -192,7 +202,7 @@ public function html_to_pdf_with_template( * @param string $mainTitle * @param bool $generateToFile Optional. When it is TRUE, then the output file is move to app/cache * - * @throws \MpdfException + * @throws MpdfException * * @return false|null */ @@ -342,7 +352,7 @@ public function html_to_pdf( $document_html = self::fixImagesPaths($document_html, $course_data, $dirName); - // The library mPDF expects UTF-8 encoded input data. + // The library Mpdf expects UTF-8 encoded input data. api_set_encoding_html($document_html, 'UTF-8'); // TODO: Maybe it is better idea the title to be passed through $title = api_get_title_html($document_html, 'UTF-8', 'UTF-8'); @@ -394,13 +404,13 @@ public function html_to_pdf( * @param bool $addDefaultCss * @param bool $completeHeader * + * @throws MpdfException + * * 'I' (print on standard output), * 'D' (download file) (this is the default value), * 'F' (save to local file) or * 'S' (return as a string) * - * @throws MpdfException - * * @return string Web path */ public function content_to_pdf( @@ -503,7 +513,7 @@ public function content_to_pdf( $document_html = str_replace(api_get_path(WEB_UPLOAD_PATH), api_get_path(SYS_UPLOAD_PATH), $document_html); $document_html = str_replace(api_get_path(WEB_ARCHIVE_PATH), api_get_path(SYS_ARCHIVE_PATH), $document_html); - // The library mPDF expects UTF-8 encoded input data. + // The library Mpdf expects UTF-8 encoded input data. api_set_encoding_html($document_html, 'UTF-8'); // At the moment the title is retrieved from the html document itself. if ($returnHtml) { @@ -787,7 +797,6 @@ public function format_pdf($courseInfo, $complete = true) */ // TODO: To be read from the html document. $this->pdf->directionality = api_get_text_direction(); - $this->pdf->useOnlyCoreFonts = true; // Use different Odd/Even headers and footers and mirror margins $this->pdf->mirrorMargins = 1; @@ -819,7 +828,7 @@ public function format_pdf($courseInfo, $complete = true) if (!empty($watermark_text)) { $this->pdf->SetWatermarkText( - strcode2utf($watermark_text), + UtfString::strcode2utf($watermark_text), 0.1 ); $this->pdf->showWatermarkText = true;