[Dompdf]: Call to undefined function mb_internal_encoding()

Updated on September 4, 2023

Recently in one of my web development project, I tried to use Dompdf and encountered error “Call to undefined function mb_internal_encoding() [DomPDF]“.

What is Dompdf?

Dompdf stands for “Document Object Model PDF,” and it works by parsing HTML and CSS, then rendering them as a PDF document. Dompdf is a PHP library that allows you to convert HTML and CSS documents to PDF format. It is often used in web development to generate PDFs dynamically from web content.

Error: [Fri Jun 16 10:30:49.244911 2023] [php7:error] [pid 819590] [client techglimpse.com:19416] PHP Fatal error: Uncaught Error: Call to undefined function Dompdf\\mb_internal_encoding() in /var/www/html/wordpress/wp-content/plugins/pdfgenerate/dompdf/vendor/dompdf/dompdf/src/Dompdf.php:295\nStack trace:\n#0 /var/www/html/wordpress/wp-content/plugins/pdfgenerate/dompdf/vendor/dompdf/dompdf/src/Dompdf.php(269): Dompdf\\Dompdf->setPhpConfig()\n#1 /var/www/html/wordpress/wp-content/plugins/pdfgenerate/formprocess.php(139): Dompdf\\Dompdf->__construct()\n#2 {main}\n thrown in /var/www/html/wordpress/wp-content/plugins/pdfgenerate/dompdf/vendor/dompdf/dompdf/src/Dompdf.php on line 295, referer: http://test.techglmpse.com/2023/05/16/test/

How to solve undefined function mb_internal_encoding while using Dompdf?

Solution: The error indicates that PHP is looking for the mb_internal_encoding() method in the Dompdf namespace. It is to Set/Get the internal character encoding. For example: mb_internal_encoding("UTF-8") is used to set the internal encoding to UTF-8. If the function is just called, mb_internal_encoding() returns the current internal character encoding.

Step 1: Install php-mbstring

# yum install php-mbstring -y

Step 2: Restart Apache service

# systemctl restart httpd

Step 3: Verify that the mbstring has been enabled using the below command or through phpinfo().

# php -i | grep mbstring
Zend Multibyte Support => provided by mbstring
Multibyte decoding support using mbstring => enabled
mbstring extension makes use of "streamable kanji code filter and converter", which is distributed under the GNU Lesser General Public License version 2.1.
mbstring.detect_order => no value => no value
mbstring.encoding_translation => Off => Off
mbstring.func_overload => 0 => 0
mbstring.http_input => no value => no value
mbstring.http_output => no value => no value
mbstring.http_output_conv_mimetypes => ^(text/|application/xhtml\+xml) => ^(text/|application/xhtml\+xml)
mbstring.internal_encoding => no value => no value
mbstring.language => neutral => neutral
mbstring.strict_detection => Off => Off
mbstring.substitute_character => no value => no value

Was this article helpful?

Related Articles

Leave a Comment