setlocale() function interferes with DOMPDF

554 views
Skip to first unread message

Sem Kurtulus

unread,
Mar 7, 2012, 1:45:31 AM3/7/12
to dom...@googlegroups.com
Hello,

I am using DOMPDF on an internationalized code and the page that
generates the html output and outputs the PDF also calls the setlocale
function to determine which language to load and if this function gets
called on the page, the PDF does not get generated.

I have found the following about it but this certainly does not help.
(not even sure if it is related)

http://code.google.com/p/dompdf/issues/detail?id=20

Any idea why this is happening? And how do I fix it?

Thank you

Sem

BrianS

unread,
Mar 7, 2012, 10:11:10 AM3/7/12
to dom...@googlegroups.com
Which version of dompdf you are using. That particular bug has been addressed in 0.6.0.

What do you mean when you say the PDF does not get generated? Do you get any errors? A blank page? A corrupted PDF?


On Wednesday, March 7, 2012 1:45:31 AM UTC-5, Sem K wrote:
Helloa,

Sem Kurtulus

unread,
Mar 7, 2012, 2:50:20 PM3/7/12
to dom...@googlegroups.com
I am using the latest greatest of the dompdf. Below is the condensed
version of the code i am executing. When this code is called, it
should be prompting me to open the PDF file but it does nothing. But
the moment i remove the setlocale line, it works.

<?PHP
session_start();

@require_once("../../dompdf/dompdf_config.inc.php");

putenv("LC_ALL=".$_SESSION['lang']);
setlocale(LC_ALL, $_SESSION['lang']);
bindtextdomain("messages", "lang");
bind_textdomain_codeset('messages', 'UTF-8');
textdomain("messages");

$html .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
$html .= '<html xmlns="http://www.w3.org/1999/xhtml">';
$html .= '<head>';
$html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
$html .= '<link rel="gettext" type="application/x-po"
href="lang/'.$_SESSION['lang'].'/LC_MESSAGES/messages.po" />';
$html .= '<link rel = "stylesheet" type = "text/css"
href="css/reports.css" media="">';

$html .= '</head>';

$html .= '<body>';

$html .= 'Some Test Here';


$html .= '</body> </html>';

$dompdf = new DOMPDF();
$dompdf->load_html($html, 'UTF-8');
$dompdf->set_paper("a4", "landscape" );
$dompdf->render();
$dompdf->stream("Management_Report.pdf");

?>

> --
> You received this message because you are subscribed to the Google Groups
> "dompdf" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/dompdf/-/ZDB8mVJXbksJ.
> To post to this group, send email to dom...@googlegroups.com.
> To unsubscribe from this group, send email to
> dompdf+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/dompdf?hl=en.
>
>

BrianS

unread,
Mar 7, 2012, 6:44:18 PM3/7/12
to dom...@googlegroups.com
On Wednesday, March 7, 2012 2:50:20 PM UTC-5, Sem K wrote:
I am using the latest greatest of the dompdf. Below is the condensed
version of the code i am executing. When this code is called, it
should be prompting me to open the PDF file but it does nothing. But
the moment i remove the setlocale line, it works.

Is this a dompdf issue or a general PHP problem? Since nothing is happening you're probably hitting a fatal error somewhere. Have you checked your error log or enabled errors to the browser (ini_set('display_errors',TRUE);) to see if PHP is throwing an error?

 

Sem Kurtulus

unread,
Mar 7, 2012, 8:44:11 PM3/7/12
to dom...@googlegroups.com
Hi Brian,

I did print out the error and here it is;

Fatal error: Interface 'IteratorAggregate' not found in
/home2/foreuni4/public_html/buyuk/dompdf/include/frame.cls.php on line
955

Thoughts?

Thanks

Sem

On 3/7/12, BrianS <eclect...@gmail.com> wrote:

> --
> You received this message because you are subscribed to the Google Groups
> "dompdf" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/dompdf/-/armpjoGSZp4J.

Sem Kurtulus

unread,
Mar 8, 2012, 10:30:31 PM3/8/12
to dom...@googlegroups.com
Hi Brian,

Any thoughts on my previous email regarding the error?

Thank you

Sem

BrianS

unread,
Mar 9, 2012, 12:55:09 PM3/9/12
to dom...@googlegroups.com
I haven't had a chance to investigate in depth yet. The referenced class is definitely missing, but I'm not sure why the error only shows up after you have used setlocale(). Hopefully I'll have a chance to investigate further in the next few days.


On Thursday, March 8, 2012 10:30:31 PM UTC-5, Sem K wrote:
Hi Brian,

Any thoughts on my previous email regarding the error?

Thank you

Sem

On 3/7/12, Sem Kurtulus wrote:
> Hi Brian,
>
> I did print out the error and here it is;
>
> Fatal error: Interface 'IteratorAggregate' not found in
> /home2/foreuni4/public_html/buyuk/dompdf/include/frame.cls.php on line
> 955
>
> Thoughts?
>
> Thanks
>
> Sem
>

Sem Kurtulus

unread,
Mar 9, 2012, 6:28:46 PM3/9/12
to dom...@googlegroups.com
Thank you Brian,

Please let me know if I can assist on any testing or debugging during
this investigation process.

Sem

> --
> You received this message because you are subscribed to the Google Groups
> "dompdf" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/dompdf/-/sJ9iJwVtPsAJ.

Sem Kurtulus

unread,
Mar 13, 2012, 12:12:36 AM3/13/12
to dom...@googlegroups.com, dom...@googlegroups.com
Hi Brian,

Do u have a timeline on this one? Our development entirely stopped due to this issue. Please let me know if I can provide any assistance to help out on this.

Thank you 

Sem
--
You received this message because you are subscribed to the Google Groups "dompdf" group.
To view this discussion on the web visit https://groups.google.com/d/msg/dompdf/-/sJ9iJwVtPsAJ.

Fabien Ménager

unread,
Mar 13, 2012, 3:02:45 AM3/13/12
to dom...@googlegroups.com
There seems to be the reason of this probleme here :  http://code.google.com/p/solr-php-client/issues/detail?id=67 
Very weird : Capital "I" letters in func/class method names do not work with turkish locale.

Sem Kurtulus

unread,
Mar 13, 2012, 3:23:13 AM3/13/12
to dom...@googlegroups.com
Hi Fabien,

Thank you for the guidance. The thing is that if you look at my code
below, I dont even have any turkish characters entered at this time.
just the inlcude that spits out that error.

Thoughts?

> --
> You received this message because you are subscribed to the Google Groups
> "dompdf" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/dompdf/-/JGhACMHg23wJ.

Sem Kurtulus

unread,
Mar 17, 2012, 1:28:01 PM3/17/12
to dom...@googlegroups.com
Hi,

Based on Fabien's comments below, I am stuck.

What should i try to get this problem resolved. Please help !

Thank you

Sem

On 3/13/12, Fabien Ménager <phenx...@gmail.com> wrote:

> In fact, you don't even have to use any turkish character, this is the fact
> that in certain locales, "i" is not equal to a lower case "I", and
> internally, PHP lowercases class and method names and the locale interferes
> with it. This is a bug in PHP, you may need to set the locale to another
> one before using dompdf.

BrianS

unread,
Mar 17, 2012, 9:43:44 PM3/17/12
to dom...@googlegroups.com
Just to follow up, what Fabien was saying is that the problem is due to a bug in PHP related to the use of setlocale(). If the locale is set to certain languages (such as Turkish) PHP is unable to match certain class names (even built-in ones) and throws an error. A quick work-around is to reset your locale to, for example, a Latin-based language prior to running DOMPDF. I modified your sample script below (see the highlight for the change):

<?PHP
session_start();

@require_once("../../dompdf/dompdf_config.inc.php");

putenv("LC_ALL=".$_SESSION['lang']);
setlocale(LC_ALL, $_SESSION['lang']);
bindtextdomain("messages", "lang");
bind_textdomain_codeset('messages', 'UTF-8');
textdomain("messages");

$html .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
$html .= '<html xmlns="http://www.w3.org/1999/xhtml">';
$html .= '<head>';
$html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
$html .= '<link rel="gettext" type="application/x-po" href="lang/'.$_SESSION['lang'].'/LC_MESSAGES/messages.po" />';
$html .= '<link rel = "stylesheet" type = "text/css" href="css/reports.css" media="">';
$html .= '</head>';
$html .= '<body>';
$html .= 'Some Test Here';
$html .= '</body> </html>';

setlocale(LC_ALL, 'en_US.UTF-8');
$dompdf = new DOMPDF();
$dompdf->load_html($html, 'UTF-8');
$dompdf->set_paper("a4", "landscape" );
$dompdf->render();
$dompdf->stream("Management_Report.pdf");
?>

It's not an ideal solution, but until the problem is fixed in PHP there aren't a lot of options. Also, since the issue is related to a bug in PHP we may very well build in a work-around for the next release. We already do some locale adjustment during processing, so this isn't out of the question.


On Saturday, March 17, 2012 1:28:01 PM UTC-4, Sem K wrote:
Hi,

Based on Fabien's comments below, I am stuck.

What should i try to get this problem resolved. Please help !

Thank you

Sem

On 3/13/12, Fabien Ménager wrote:


> In fact, you don't even have to use any turkish character, this is the fact
> that in certain locales, "i" is not equal to a lower case "I", and
> internally, PHP lowercases class and method names and the locale interferes
> with it. This is a bug in PHP, you may need to set the locale to another
> one before using dompdf.
>
> On Tuesday, March 13, 2012 8:23:13 AM UTC+1, Sem K wrote:
>>
>> Hi Fabien,
>>
>> Thank you for the guidance. The thing is that if you look at my code
>> below, I dont even have any turkish characters entered at this time.
>> just the inlcude that spits out that error.
>>
>> Thoughts?
>>

>> On 3/13/12, Fabien Ménager wrote:

Sem Kurtulus

unread,
Mar 17, 2012, 9:47:24 PM3/17/12
to dom...@googlegroups.com
Thank you Brian and Fabien !!

Please let me know if you guys develop something for this, i have a
feeling this is a very common use and i am suprised that PHP dev is
not doing anything about it...

in the meantime, i will set locale back to english.

Respectfully,

Sem

> --
> You received this message because you are subscribed to the Google Groups
> "dompdf" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/dompdf/-/vHwe48wDv0sJ.

BrianS

unread,
Mar 18, 2012, 10:37:20 PM3/18/12
to dom...@googlegroups.com
FYI, a bug has been filed. You can star that issue to see when new information is available.


On Saturday, March 17, 2012 9:47:24 PM UTC-4, Sem K wrote:
Thank you Brian and Fabien !!

Please let me know if you guys develop something for this, i have a
feeling this is a very common use and i am suprised that PHP dev is
not doing anything about it...

in the meantime, i will set locale back to english.

Respectfully,

Sem

Reply all
Reply to author
Forward
0 new messages