mPDF Manual – mPDF Variables

allow_charset_conversion

(mPDF >= 1.0)

Description

boolean allow_charset_conversion

When true, mPDF will attempt to parse the character set of any input HTML. You can also use it together with $charset_in to manually set an input encoding.

Values

$allow_charset_conversion = true|false

Values

  • true: Parse the character set of any input text from the HTML, or allow setting of the value $charset_in

  • false: Expect all text input as UTF-8 encoding.

Default: true

Usage

Set at document initiation

<?php
$mpdf = new \Mpdf\Mpdf(['allow_charset_conversion' => true]);

or during the course of creating the document

<?php
$mpdf->allow_charset_conversion = true;

Examples

Example #1

<?php

$html = '

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-4" />
    <title>Document in Lithuanian</title>
</head>
<body>

... the body of the document encoded in ISO-8859-4 ...

</body>
</html>';

$mpdf = new \Mpdf\Mpdf(['allow_charset_conversion' => true]);

$mpdf->WriteHTML($html);
$mpdf->Output();

Example #2

<?php

$html = '... the body of the document encoded in ISO-8859-4 ...';

$mpdf = new \Mpdf\Mpdf();

$mpdf->allow_charset_conversion = true;
$mpdf->charset_in = 'iso-8859-4';
$mpdf->WriteHTML($html);

$mpdf->Output();

See Also

Fork me on GitHub