FontAwesome Icons won't Show on Generated PDF using mPDF

前端 未结 1 896
夕颜
夕颜 2020-12-22 05:09

I am using mPDF in generating payslips. However, the icons in the payslip aren\'t showing once it is generated. It only leaves a blank space just like this:

相关标签:
1条回答
  • 2020-12-22 05:40

    Encoding issues aside, this could be a couple of things. Firstly, you need to integrate FontAwesome with your MPDF installation. Secondly, you need to consider how you're speficiying the glyph in HTML.

    Installing FontAwesome in mPDF

    Download or clone FontAwesome from https://github.com/FortAwesome/Font-Awesome and copy fonts/fontawesome-webfont.ttf into your MPDF ttfonts/ directory.

    In your MDPF config_fonts.php file, add the following lines to $this->fontdata:

     /* FontAwesome */
        "fontawesome" => array(
            'R' => "fontawesome-webfont.ttf"
            ),
    

    Adding the glyph in HTML

    You need to keep in mind that the CSS :before pseudo-selector commonly used to add FontAwesome glyphs to HTML doesn't work in mPDF.

    Bad:

    <i class="fa fa-smile-o"></i>
    

    ... because this FontAwesome CSS rule doesn't work in mPDF:

    .fa-smile-o:before {
      content: "\f118";
    }
    

    Good:

    <i class="fa">&#xf118;</i>
    

    You can get the unicode code point for each glyph by clicking on it on the FontAwesome Icon List, but the Cheatsheet is more convenient for this.

    0 讨论(0)
提交回复
热议问题