2
2
/* See license terms in /license.txt */
3
3
4
4
use Chamilo \CoreBundle \Component \Utils \ChamiloApi ;
5
+ use Mpdf \Mpdf ;
6
+ use Mpdf \MpdfException ;
7
+ use Mpdf \Utils \UtfString ;
5
8
6
9
/**
7
10
* Class PDF.
8
11
*/
9
12
class PDF
10
13
{
11
- /** @var mPDF */
14
+ /** @var Mpdf */
12
15
public $ pdf ;
13
16
public $ custom_header = [];
14
17
public $ custom_footer = [];
15
18
public $ params = [];
16
19
public $ template ;
17
20
18
21
/**
19
- * Creates the mPDF object.
22
+ * Creates the Mpdf object.
20
23
*
21
24
* @param string $pageFormat format A4 A4-L see
22
25
* http://mpdf1.com/manual/index.php?tid=184&searchstring=format
23
26
* @param string $orientation orientation "P" = Portrait "L" = Landscape
24
27
* @param array $params
25
28
* @param Template $template
29
+ *
30
+ * @throws MpdfException
26
31
*/
27
32
public function __construct (
28
33
$ pageFormat = 'A4 ' ,
@@ -31,7 +36,7 @@ public function __construct(
31
36
$ template = null
32
37
) {
33
38
$ this ->template = $ template ;
34
- /* More info @ http://mpdf1.com/manual/index.php?tid=184&searchstring=mPDF */
39
+ /* More info @ http://mpdf1.com/manual/index.php?tid=184&searchstring=Mpdf */
35
40
if (!in_array ($ orientation , ['P ' , 'L ' ])) {
36
41
$ orientation = 'P ' ;
37
42
}
@@ -58,18 +63,21 @@ public function __construct(
58
63
$ this ->params ['pdf_date ' ] = isset ($ params ['pdf_date ' ]) ? $ params ['pdf_date ' ] : api_format_date ($ localTime , DATE_TIME_FORMAT_LONG );
59
64
$ this ->params ['pdf_date_only ' ] = isset ($ params ['pdf_date ' ]) ? $ params ['pdf_date ' ] : api_format_date ($ localTime , DATE_FORMAT_LONG );
60
65
61
- @$ this ->pdf = new mPDF (
62
- 'UTF-8 ' ,
63
- $ pageFormat ,
64
- '' ,
65
- '' ,
66
- $ params ['left ' ],
67
- $ params ['right ' ],
68
- $ params ['top ' ],
69
- $ params ['bottom ' ],
70
- 8 ,
71
- 8 ,
72
- $ orientation
66
+ $ this ->pdf = new Mpdf (
67
+ [
68
+ 'mode ' => 'UTF-8 ' ,
69
+ 'format ' => $ pageFormat ,
70
+ 'default_font_size ' => '' ,
71
+ 'default_font ' => '' ,
72
+ 'margin_left ' => $ params ['left ' ],
73
+ 'margin_right ' => $ params ['right ' ],
74
+ 'margin_top ' => $ params ['top ' ],
75
+ 'margin_bottom ' => $ params ['bottom ' ],
76
+ 'margin_header ' => 8 ,
77
+ 'margin_footer ' => 8 ,
78
+ 'orientation ' => $ orientation ,
79
+ 'tempDir ' => api_get_path (SYS_ARCHIVE_PATH ).'mpdf/ ' ,
80
+ ]
73
81
);
74
82
75
83
$ this ->pdf ->margin_footer = $ params ['margin_footer ' ];
@@ -92,7 +100,9 @@ public function __construct(
92
100
* @param bool $addDefaultCss (bootstrap/default/base.css)
93
101
* @param array
94
102
*
95
- * @return string
103
+ * @throws MpdfException
104
+ *
105
+ * @return string|null
96
106
*/
97
107
public function html_to_pdf_with_template (
98
108
$ content ,
@@ -192,7 +202,7 @@ public function html_to_pdf_with_template(
192
202
* @param string $mainTitle
193
203
* @param bool $generateToFile Optional. When it is TRUE, then the output file is move to app/cache
194
204
*
195
- * @throws \ MpdfException
205
+ * @throws MpdfException
196
206
*
197
207
* @return false|null
198
208
*/
@@ -342,7 +352,7 @@ public function html_to_pdf(
342
352
343
353
$ document_html = self ::fixImagesPaths ($ document_html , $ course_data , $ dirName );
344
354
345
- // The library mPDF expects UTF-8 encoded input data.
355
+ // The library Mpdf expects UTF-8 encoded input data.
346
356
api_set_encoding_html ($ document_html , 'UTF-8 ' );
347
357
// TODO: Maybe it is better idea the title to be passed through
348
358
$ title = api_get_title_html ($ document_html , 'UTF-8 ' , 'UTF-8 ' );
@@ -394,13 +404,13 @@ public function html_to_pdf(
394
404
* @param bool $addDefaultCss
395
405
* @param bool $completeHeader
396
406
*
407
+ * @throws MpdfException
408
+ *
397
409
* 'I' (print on standard output),
398
410
* 'D' (download file) (this is the default value),
399
411
* 'F' (save to local file) or
400
412
* 'S' (return as a string)
401
413
*
402
- * @throws MpdfException
403
- *
404
414
* @return string Web path
405
415
*/
406
416
public function content_to_pdf (
@@ -503,7 +513,7 @@ public function content_to_pdf(
503
513
$ document_html = str_replace (api_get_path (WEB_UPLOAD_PATH ), api_get_path (SYS_UPLOAD_PATH ), $ document_html );
504
514
$ document_html = str_replace (api_get_path (WEB_ARCHIVE_PATH ), api_get_path (SYS_ARCHIVE_PATH ), $ document_html );
505
515
506
- // The library mPDF expects UTF-8 encoded input data.
516
+ // The library Mpdf expects UTF-8 encoded input data.
507
517
api_set_encoding_html ($ document_html , 'UTF-8 ' );
508
518
// At the moment the title is retrieved from the html document itself.
509
519
if ($ returnHtml ) {
@@ -787,7 +797,6 @@ public function format_pdf($courseInfo, $complete = true)
787
797
*/
788
798
// TODO: To be read from the html document.
789
799
$ this ->pdf ->directionality = api_get_text_direction ();
790
- $ this ->pdf ->useOnlyCoreFonts = true ;
791
800
// Use different Odd/Even headers and footers and mirror margins
792
801
$ this ->pdf ->mirrorMargins = 1 ;
793
802
@@ -819,7 +828,7 @@ public function format_pdf($courseInfo, $complete = true)
819
828
820
829
if (!empty ($ watermark_text )) {
821
830
$ this ->pdf ->SetWatermarkText (
822
- strcode2utf ($ watermark_text ),
831
+ UtfString:: strcode2utf ($ watermark_text ),
823
832
0.1
824
833
);
825
834
$ this ->pdf ->showWatermarkText = true ;
0 commit comments