I am trying to export a document to PDF using Laravel & DomPDF. This works on my mac, but not on staging or live server. Error as follows:
I have no idea what this means, and cannot find any solutions.
iconv_strlen(): Wrong charset, conversion from8bit//IGNORE' to UCS-4LE' is not allowed
open: /srv/www/html/vendor/patchwork/utf8/class/Patchwork/PHP/Shim/Mbstring.php
return true;
}
static function mb_strlen($s, $encoding = INF)
{
INF === $encoding && $encoding = self::$internal_encoding;
return iconv_strlen($s, $encoding . '//IGNORE');
}
I have tried adding the following to .htaccess
AddDefaultCharset UTF-8
I have tried adding the following to the top of the view which I am trying to generate the pdf for:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
If you need any further information to assist me in debugging, please ask in comments.
Problem solved. Thanks BrianS.
This was solved by re-installing mbstring.
sudo yum --disablerepo="*" --enablerepo="remi*"
install php-mbstring*
sudo httpd -k restart
BrianS's solution does indeed solve the issue, but I thought it'd be interesting to explain what caused the original problem.
In the latest release of dompdf,
the Cpdf class
contains about 30 calls to mb_strlen() with the $encoding parameter set to '8bit', which is a
valid encoding for mb_strlen().
Laravel's composer.json
requires patchwork/utf8. It provides the mb_strlen() shim
which calls iconv_strlen().
PHP usually uses either glibc or libiconv for its iconv module.
For both libraries, the list of supported encodings can be
displayed using iconv --list.
Neither of those libraries support an encoding called '8bit', which is why iconv_strlen()
throws that error:
Wrong charset, conversion from '8bit//IGNORE' to 'UCS-4LE' is not allowed
Installing the mbstring PHP module causes mb_strlen() to be executed natively,
so the shim isn't used and the error doesn't occur.
@rofavadeka One solution is to create a
fork of the
dompdf repo, and replace every use of
'8bit' encoding with a different 8-bit encoding which is supported by
mb_strlen(), glibc and libiconv.
I've written a script to determine which encodings are suitable.
Here's the output of the script for
glibc and
libiconv.
The suitable encodings are:
cp850cp866iso-8859-1iso-8859-2iso-8859-4iso-8859-5iso-8859-9iso-8859-10iso-8859-13iso-8859-14iso-8859-15iso-8859-16koi8-rkoi8-uI was getting that error in Hash:make() during seeding my DB for testing.
Enabling php_mbstring in php-cli.ini caused it.
In Windows the solution is: remove the semicolon before
extension=php_mbstring.dll
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With