Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Julekot's avatar

Problem with dompdf library

Hi guys!

So I have a website that dynamically retrieves data from the form and has to display them in PDF using the dompdf library. The problem occurs when there is "enter" in the textbox, the library simply does not display it. e.g.

What is in the textbox:

Hi im trying to make PDF using dompdf library.

What is dompdf showing:

Hi im trying to make PDF using dompdf library.

I've tried:

{{$notes = nl2br($order->note)}} //It is just showing the <br /> instead of actually doing something
{{$space = '&#13'}} //giving the viable the value of strong enter
{{$note = str_replace("<br />", $space, $notes)}} // trying to replace <br /> with strong enter
<td class="padding-bottom note">{{$note}}</td> // It shows &#13 instead of "\n"

Does anybody know the solution?

Best Regards Julek

0 likes
1 reply
click's avatar
click
Best Answer
Level 35

If you only want to show newlines and not any other html do:

{!! nl2br(e($order->note)) !!}

First it escapes the note so all other html tags are escaped and it is save to display. Than it converts all new lines to <br /> tags. And because {!! does not escape your variable you keep the html variant of <br />

1 like

Please or to participate in this conversation.