Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

php - html tags in report PDF from HTML in Laravel

i have a laravel project where I need to print a pdf. I made the printing without problems, using a library DOMPDF, but inside the pdf i need to print a content of a Rich Text Area.

The UI:

enter image description here

The output is

Note
<p><b>Test</b></p><p><b><br></b></p><ul><li><b>Test 1</b></li><li><b>Test 2</b></li></ul><p><br></p>

The blade page have:

<div class="row">
        <div class="col-xs-12">
            <h4>Note</h4>
            {{$plan->note}}
        </div>
    </div>

How can i print the html content correctly?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Basically Laravel does html entity encoding when you print something using {{ $plan->note }}.

In order to not to encode HTML elements, you have to use

{!! $plan->note !!}

This is not only for PDF. It can be used for web page rendering as well.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...