mPDF - Error generating PDF | Message: preg_replace():

Asked

Viewed 1,621 times

4

I’m using mPDF to generate the PDF:

    $this->load->helper('mpdf');
    $this->data['dadosboleto'] = $this->boleto_model->GerarBoletoCEF($id_cliente, $data_inicial, $data_final);
    $this->data['view'] = 'boleto/boleto';
    $this->load->view('tema/topo',$this->data);
    $html = $this->load->view('boleto/boleto_impressao', $this->data, true);
    pdf_create($html, 'boleto_'.$id_cliente."_". date('d-m-Y'), TRUE);

The error you make when generating is:

PHP Error was encountered

Severity: 8192 Message: preg_replace(): The /e Modifier is deprecated, use preg_replace_callback Instead Filename: mpdf/mpdf.php Line Number: 31592

This error only happens if I have HTML inside the View being generated, if I have only one echo "teste" it works normally.

I’m using the Codeigniter framework.

Addendum:

Based on our friend Yure’s answer, it stayed that way:

inserir a descrição da imagem aqui

And this would be the way to appear correctly in the PDF:

inserir a descrição da imagem aqui

What can it be? Here is the view: http://pastebin.com/FZ0apNcy for being very extensive, I preferred to put in Pastebin.

  • 1

    As you can see in the warning, the function preg_replace() this depreciated ie, it is no longer recommended to use it because the function preg_replace_callback this replacing it, you can consult the php documentation for more information http://php.net/manual/en/function.preg-replace-callback.php

  • Hmmmm, but how do I do it? Because it’s a file of 32,000 lines or so that gave this error... You can post an example?

  • 1

    Try to get the latest version of mPDF maybe this error has already been fixed.

  • 1

    In fact, it is not the preg_replace() function that is depreciated, but rather the use of the modifier and along with it, where it is recommended to use the preg_replace_callback() function in these cases..

  • @Yurepereira yes... that’s what I imagined, because when I pass a test parameter only, that is, an echo "test", comes the normal PDF... but when I print something in html and php, it presents the error

  • @Andrebaill Tries to use the ob_clean() function to clear the output buffer.

  • Where I put?

  • Could be a problem with my CSS @Yurepereira ?

  • Before calling $mpdf->Output method();

Show 5 more comments

2 answers

3

As quoted in the comments, the modifier e(Eval) of the functions preg_* was discontinued in php5.5 and removed in 7.0, instead it should use function preg_replace_callback().

To fix the problem, open the problem file, replace the lines with the modifier e by the code below:

$str = preg_replace_callback('/\&\#([0-9]+)\;/m', function($m) use ($lo){return code2utf($m[1],$lo); }, $str);
$str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', function($m) use ($lo){return codeHex2utf($m[1],$lo);}, $str);

Based on: mpdf error - preg_replace(): The /e Modifier is deprecated, use preg_replace_callback Instead

  • I made this proposed change. But the error that was generated was the one I quoted earlier.

  • @Andrébaill error was in the same file and line even with the change?

  • First the mistake was in this line and I changed. Ai gave error that I mentioned before... So

1


Try to use as follows to not display the error, but you could also update the library to its latest version:

    error_reporting(E_ALL ^ E_DEPRECATED);

    $this->load->helper('mpdf');
    $this->data['dadosboleto'] = $this->boleto_model->GerarBoletoCEF($id_cliente, $data_inicial, $data_final);
    $this->data['view'] = 'boleto/boleto';
    $this->load->view('tema/topo',$this->data);
    $html = $this->load->view('boleto/boleto_impressao', $this->data, true);
    pdf_create($html, 'boleto_'.$id_cliente."_". date('d-m-Y'), TRUE);
  • With your answer, it even generates what I need, however, when generating the lines do not work, and are misaligned, however, the view appears straight..

  • I modified my question based on your answer @Yurepereira

  • I managed using your answer, but instead of putting #000000 on the edge in CSS, I used BLACK. I don’t know why, but it worked. Thank you so much for your help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.