4

I used DOMPDF library and now I have problem with content with unicode language. and I found this one dompdf help but I don't understand about this. can anyone tell the detail of this? thanks

1

5 Answers 5

10
  1. Enable the mbstring extension
  2. Find a font in .ttf format with characters that support your given language
  3. Generate a .afm file for DOMPDF:
    1. Using the command line, cd into the directory which contains load_font.php, then run php load_font.php FontName /path/to/font.ttf
    2. Using the online tool, fill out the form and download the zip it gives you. Copy the files from this zip into dompdf/lib/fonts. If you've done this before, add relevant lines to dompdf_font_family_cache, otherwise simply rename the dompdf_font_family_cache.sample to dompdf_font_family_cache
  4. Enable DOMPDF's Unicode mode, by making sure the line

    define("DOMPDF_UNICODE_ENABLED", true);
    

    is set in dompdf_config.inc.php. If it reads false instead of true, change that.

6
  • 1
    I got message: Unable to locate the ttf2afm / ttf2pt1 executable (checked /home/piseth/dev/example/pdf_php/lib/ttf2ufm/ttf2ufm-src/ttf2pt1).
    – Piseth Sok
    Jan 23, 2012 at 9:32
  • Sounds like you need to install tt2afm or tt2pt1. Try ttf2pt1.sourceforge.net
    – Ryan McCue
    Jan 23, 2012 at 10:54
  • I tried your instruction, but it doesn't work. I read in another topic that I should add css about font family to the print.tpl and it really works then.
    – deem
    Aug 6, 2013 at 13:07
  • I followed the above instruction, but not work for me.
    – Mr. Tomar
    Mar 5, 2016 at 6:16
  • 1
    when i generate the pdf form html which contain burmese language( நான் என் முதலாளி வீட்டில் ஜன்னல்கள் வெளிப்புறம் சுத்தம் செய்ய தேவையில்லை என்று புரிந்துகொள்ளுங்கள் . ) then in pdf its show ???????????????????????????????????????????????
    – Mr. Tomar
    Mar 5, 2016 at 6:18
3

There is a wiki page for this.

The next beta (0.6 beta 3), to be released soon, has a font installer that doesn't require the command line (neither any compilation). You already can use it by checking out the SVN trunk. This beta also supports @font-face.

2
  • The SVN trunk not work I have def("DOMPDF_UNICODE_ENABLED", true); change this also but still not work.
    – Piseth Sok
    Jan 23, 2012 at 9:47
  • @user970587 it would help to see a sample of the code you're attempting to render (and more detail about what you've tried)
    – BrianS
    Jan 24, 2012 at 17:38
1

As of version 0.7, dompdf supports and has unicode enabled by default. (therefore there is no need for configuration).

Not all dompdf fonts support unicode though. I used font-family: DejaVu Sans with success.

To install a custom font or learn more about it you can read the official unicode how to.

1

Download load_font.php and place in ur project root

View load_font.php

add $fontDir = "storage/fonts";

This will show where the fonts are added.

download your font at eg: PREETI and place at your project root

run in command line php load_font.php PREETI PREETI.ttf

then you font will be installed to storage/fonts directory

now go to the pdf file and add

<style>
    body {
        font-family: PREETI;
        color: #1c2221;
    }
</style>
1
  • run in command line php load_font.php PREETI PREETI.ttf=>how do I run this ..command in browser or in php program ... I want to use in website pls help..command line is for window?..I wish to install for website Nov 5, 2022 at 19:12
-1

try to manipulate your code using this recommended DOMPDF method it's a A guide to enabling Unicode support in DOMPDF To ensure maximum compatibility you should follow all of the following steps. Click through for additional details. Ensure the MBString PHP extension is enabled Install dompdf 0.6.0 or greater Configure dompdf for Unicode support Load a font supporting your characters into dompdf Create a compatible HTML document see the link for more information

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.