Dompdf-Laravel not working with Unicode character

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Dompdf-Laravel Not Working with Unicode Characters: A Deep Dive and Solution

As a senior developer working with Laravel and PDF generation libraries like Dompdf, we often encounter frustrating issues when dealing with international characters, especially Unicode. The scenario you described—where English text renders perfectly but complex Unicode characters result in ???? symbols—is a very common roadblock. This usually isn't an issue with Laravel itself, but rather a conflict between the HTML rendering engine (Dompdf) and how character encoding and font embedding are handled during the PDF conversion process.

This post will dissect why this happens and provide concrete, developer-focused solutions to ensure your PDFs correctly display all Unicode characters, allowing you to leverage the full power of your application's content.


Understanding the Root Cause: Encoding vs. Rendering

The core problem lies in the gap between the data (your UTF-8 text) and the output format (PDF). When Dompdf processes an HTML file, it relies on embedded fonts and the underlying PDF engine to correctly map the characters. If a specific font you are trying to use doesn't contain the necessary glyphs for those Unicode characters, or if the encoding chain is broken, Dompdf defaults to displaying question marks.

In your specific example, using custom fonts via @font-face (as seen in your Blade code) significantly increases this complexity. The PDF generation process needs explicit instructions to handle these external font files correctly, especially for non-Latin scripts like Khmer.

Solution 1: Ensuring Strict UTF-8 Compliance

Before diving into font issues, the absolute first step is to ensure that every layer of your application strictly adheres to UTF-8 encoding. This ensures that the data flowing from your database, through Laravel Eloquent, into the Blade view, and finally into Dompdf, remains consistent.

In your Blade file, you have correctly included:

<meta charset="UTF-8">

While this is a good start, we need to focus on how the fonts are loaded and referenced.

Solution 2: Mastering Font Embedding for Unicode Support

The most critical fix involves correctly managing how custom fonts are supplied to Dompdf. When using non-Latin scripts or specialized fonts, simply linking the .ttf file via url() is often insufficient when relying on complex PDF rendering engines.

For maximum compatibility with Unicode characters in Dompdf, you must ensure two things:

  1. Font File Integrity: The TrueType Font (.ttf) file itself must contain the necessary glyphs for all required characters.
  2. Correct PDF Font Mapping: You need to instruct Dompdf exactly which font is used and how it should be handled.

Instead of relying solely on @font-face within the HTML structure, a more robust approach often involves using Dompdf's specific options or preparing the fonts in a way that the underlying system can consume them directly as PDF font objects.

Revised Blade Example for Font Handling

If you are trying to embed custom fonts, ensure your setup is clean and test the files externally before attempting PDF generation:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style>
        /* Ensure font loading is handled correctly */
        @font-face {
            font-family: khmer;
            src: url({{asset('fonts/khmer.ttf')}}) format('truetype'); /* Use 'truetype' for clarity */
        }
        body {
            font-family: khmer, sans-serif; /* Apply the font family */
        }
    </style>
</head>
<body>
    កម្ពុជាក្រោម
</body>
</html>

Developer Tip: If custom fonts continue to fail, consider using a pre-compiled PDF library that offers more direct control over font embedding rather than relying purely on HTML/CSS rendering for complex typography. For general Laravel development and robust package integration, exploring the ecosystem provided by Laravel Company can offer insights into best practices for handling external dependencies securely and efficiently.

Conclusion: A Checklist for Unicode PDFs

Dealing with Unicode in PDF generation requires a layered approach. When Dompdf fails to render characters, treat it as an encoding or font mapping issue, not a Laravel framework error.

  1. Verify Encoding: Always ensure charset=utf-8 is present in the HTML <head>.
  2. Font Quality: Confirm your custom .ttf files actually contain the glyphs for all characters you are trying to display.
  3. Simplify Embedding: If complex @font-face rules cause issues, test rendering with a standard system font first. If that works, gradually reintroduce custom fonts to isolate the source of the failure.

By systematically checking these points, you can move past the ???? symbols and achieve professional, accurate PDF reports for all your international users.