Laravel Dom PDF issues with font awesome and a Unicode work around

So I am using Laravel-DomPDF by Barryvdh in my Laravel 5.4 project, which makes it super easy to create PDF documents from Laravel Views.

Kudos to Barryvdh for providing a simple way to produce PDF documents from Laravel.

So, I wanted to pull Font Awesome into the blade view for a couple of icons I had on the page.  Problem was that it was not working.  I tried everything suggested from full url for the link, to adding a fonts folder to /storage/app.  None worked for me.

As I only need a tick and an exclamation on the page I decided to add the styles straight into the head of my blade file and use Unicode.

I found that Dom PDF already pulls in DeJaVu Fonts which is a project that is aiming for complete coverage of alphabetic scripts. The other thing is that it has a bunch of symbols.  Not as awesome as Font Awesome but enough for my needs.

In between the head tags I added this.

<style>
.fa-check:before {
            font-family: DejaVu Sans;
            content: "\2611";
            color:darkgreen;
            font-size:1.2rem;
}
.fa-exclamation-triangle:before{
            font-family: DejaVu Sans;
            content: "\26A0";
            color:darkorange;
            font-size:1.2rem;
 }
</style>

This is the check:

And this is the exclamation:

Neat hey! Where did I get the content:”\????” from?

Miscellaneous_Symbols

This was a quick and dirty solution to my issue and may help you.  While I agree it’s not ideal it is better than changing to another PDF project or spending more time trying to get this to work with Font Awesome at the moment.

Leave a Reply

Your email address will not be published. Required fields are marked *