I would like you to help me with this issue, I’m dealing for the first time with mPDF which I think it’s great, but I want to display the report with the same type of font as my web, which on its documentations explains how to achieve this, but it doesn’t still seems to work for me. What I did till now is:
- Add the url to Open Sans from google to my document which will be
generated after it,
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
. then I add a style sheet file that contains the use of the font
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/publicidad/css/reporte.css" type="text/css">
Inside reporte.css that I’ve already added, I have a definition to use ‘Open Sans’ fontbody { font-family: ‘Open Sans’, Sans-Serif; } which displays the font as expected.
- I Generate the pdf with mPDF which works well but when I want to
display the Open Sans as the documentation stands, it’s not showing the desired font, I downloaded the ttfs file of ‘Open Sans’ from http://www.fontsquirrel.com/fonts/open-sans, and added inside ttfonts folder of mPDF directory as it says within its documentation.
After it I follow this clear documentation http://mpdf1.com/manual/index.php?tid=453, but till now I’m not getting the desired font displayed in my PDF document what I didn’t do till now its the part that says “4. To use the font with specific languages, you need also to edit the configuration file (config_cp.php); let us imagine that Frutiger contains a full set of characters needed for the Thai language:”, but I don’t think that’s the problem because I’m using a default configuration which I put down.
function pdf_create($html, $filename, $stream = TRUE) { require_once(APPPATH . 'helpers/mpdf/mpdf.php'); $mpdf = new mPDF(); $mpdf->SetAutoFont(); $mpdf->WriteHTML($html); if ($stream) { $mpdf->Output($filename . '.pdf', 'D'); } else { $mpdf->Output('./uploads/temp/' . $filename . '.pdf', 'F'); return './uploads/temp/' . $filename . '.pdf'; } }
and in my controller I do this.
$html = $this->load->view('publicidad/reporte_x_curso', $data, true); $this->load->helper('mpdf'); pdf_create($html, 'Reporte_por_cursos', true);
(the above isn’t being recognized by the stackverflow editor)
And finally what I did till now that should do all I want following the documentation is:
$this->fontdata = array( "'Open Sans'" => array( 'R' => 'OpenSans-Regular.ttf' )
PD: I put the single quotes because I was adding that way in my html document, but I also tried without them, without success. I hope you can help me, thanks in advance.
Advertisement
Answer
I’ve solved my problem, there should be no spaces in the definition of the font, so I replaced in my css font-face declaration with “opensans” and
$this->fontdata = array( "opensans" => array( 'R' => 'OpenSans-Regular.ttf' )
be aware that the font type (‘OpenSans-Regular.ttf’) should be inside ttfonts folder of mpdf folder