title: How to fix unicode utf-8 when export content to PDF on laravel 7 with dompdf?
body: <p>I created a function to export download PDF files with Laravel dompdf. I have a bug with UTF-8 Unicode for the Japanese language. The pdf file displays incorrect the Japanese language. When I copy the text in the PDF to the word file it can display correctly. This is the pdf file <a href="http://inofthing.com/element_list_pdf.pdf" rel="nofollow noreferrer">http://inofthing.com/element_list_pdf.pdf</a></p>
  
  <p><a href="https://i.stack.imgur.com/l1VC8.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l1VC8.jpg" alt="enter image description here"></a></p>
  
  <p>I created a function in controller and view to generate the pdf and download as below.</p>
  
  <p>The controller:</p>
  
  <pre><code>public function exportPdf(Request $request)
      {
          $project_id = $request-&gt;project_id;
  
          // Fetch all element from database
          $data = DB::table('element_designs')
              -&gt;join('elements', function($join){
                  $join-&gt;on('element_designs.id', '=', 'elements.element_design_id')
                      -&gt;where('elements.deleted_at', null);
              })
  
              -&gt;leftJoin('tag_mappings', function($join){
                  $join-&gt;on('elements.id' , '=', 'tag_mappings.element_id')
                      -&gt;where('tag_mappings.deleted_at', null);
              })
              -&gt;leftJoin('rfid_tags', function($join){
                  $join-&gt;on('tag_mappings.tag_id', '=', 'rfid_tags.id')
                      -&gt;where('rfid_tags.disable_flg', false);
              })
              -&gt;leftJoin('districts', function($join){
                  $join-&gt;on('element_designs.district_id', '=', 'districts.id')
                      -&gt;where('districts.disable_flg', false);
              })
              -&gt;leftJoin('statuses', function($join){
                  $join-&gt;on('elements.status_id', '=', 'statuses.id')
                      -&gt;where('statuses.disable_flg', false);
              })
              -&gt;leftJoin('locations', function($join){
                  $join-&gt;on('elements.location_id', '=', 'locations.id')
                      -&gt;where('locations.disable_flg', false);
              })
              -&gt;leftJoin('areas', function($join){
                  $join-&gt;on('elements.area_id', '=', 'areas.id')
                      -&gt;where('areas.disable_flg', false);
              })
              -&gt;leftJoin('delivery_date_mappings', function($join){
                  $join-&gt;on('elements.id', '=', 'delivery_date_mappings.element_id')
                      -&gt;where('delivery_date_mappings.deleted_at', null);
              })
              -&gt;leftJoin('delivery_dates', function($join){
                  $join-&gt;on('delivery_date_mappings.delivery_date_id', '=', 'delivery_dates.id')
                      -&gt;where('delivery_dates.disable_flg', false);
              })
              -&gt;where('element_designs.disable_flg', false)
              -&gt;where('element_designs.project_id', $project_id)
              -&gt;orderBy('element_designs.id')
              -&gt;select('element_designs.id as element_design_id', 'element_designs.doc_no', 'elements.id as element_id', 'element_designs.project_id as project_id',
                  'tag_mappings.created_at as create_time', 'tag_mappings.id as tag_mappings_id', 'element_designs.element_name', 'elements.element_seq_id',
                  'districts.district_name', 'element_designs.material_name', 'element_designs.element_size', 'element_designs.element_length', 'element_designs.single_weight', 'element_designs.remarks',
                  'element_designs.total_weight', 'rfid_tags.device_id', 'statuses.status_name', 'locations.location_name', 'areas.area_name',
                  'elements.latitude', 'elements.longitude', 'delivery_date_mappings.delivery_date_id', 'delivery_dates.delivery_date',
                  'elements.updated_at', 'statuses.status_name', 'statuses.id as statuses_id')
              -&gt;paginate(100);
  
          // Send data to the view using loadView function of PDF facade
          $view = view('element.pdf', ['items' =&gt; $data]);
          $html = mb_convert_encoding($view, 'HTML-ENTITIES', 'UTF-8');
          $html_decode = html_entity_decode($html);
          $pdf = \PDF::loadHTML($view)
              -&gt;setPaper('a4', 'landscape')
              -&gt;setWarnings(false)
              -&gt;setOptions(['isFontSubsettingEnabled' =&gt; true]);
  
          // Store pdf file in the server
          return $pdf-&gt;download('element_list.pdf');
          //return view('element.pdf', ['items' =&gt; $data]);
      }
  </code></pre>
  
  <p>The view:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;
      &lt;title&gt;Export element list to PDF&lt;/title&gt;
      &lt;style type="text/css"&gt;
          /*@import url(https://fonts.googleapis.com/css?family=Kosugi);*/
          /*Nunito font*/
          /*@import url(//fonts.googleapis.com/earlyaccess/notosansjapanese.css);
          @font-face {
              !*font-family: "Noto Sans", "Noto Sans CJK JP", sans-serif;*!
              font-family: 'Noto Sans Japanese', sans-serif;
              src: url({{ storage_path('fonts/NotoSansJP-Regular.otf') }}) format("otf");
              font-weight: normal;
              font-style: normal;
              font-size: 8px;
          }*/
          /*Nunito font
          * @import url(https://fonts.googleapis.com/css?family=Nunito);
          */
          /* vietnamese */
          @font-face {
              font-family: 'Nunito';
              font-style: normal;
              font-weight: 400;
              src: local('Nunito Regular'), local('Nunito-Regular'), url({{ storage_path('fonts/XRXV3I6Li01BKofIOuaBXso.woff2')}}) format('woff2');
              unicode-range: U+0102-0103, U+0110-0111, U+1EA0-1EF9, U+20AB;
          }
          /* latin-ext */
          @font-face {
              font-family: 'Nunito';
              font-style: normal;
              font-weight: 400;
              src: local('Nunito Regular'), local('Nunito-Regular'), url({{ storage_path('fonts/XRXV3I6Li01BKofIO-aBXso.woff2')}}) format('woff2');
              unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
          }
          /* latin */
          @font-face {
              font-family: 'Nunito';
              font-style: normal;
              font-weight: 400;
              src: local('Nunito Regular'), local('Nunito-Regular'), url({{ storage_path('fonts/XRXV3I6Li01BKofINeaB.woff2')}}) format('woff2');
              unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
          }
          /*End nunito fonts*/
  
          *{
              font-family: 'Nunito', sans-serif;
  
          }
          body {
              font-family: 'Nunito', sans-serif;
              font-size: 8px;
          }
          .table {
              border-collapse: collapse;
              width: 100%;
          }
  
          .table td, .table th {
              border: 1px solid #000000;
              padding: 8px;
          }
  
          .table tr:nth-child(even){}/*background-color: #f2f2f2;*/
  
          .table tr:hover {}/*background-color: #ddd;*/
  
          .table th {
              padding-top: 12px;
              padding-bottom: 12px;
              text-align: left;
              background-color: #fff6a1;
              font-weight: normal;
          }
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;table class="table table-striped"&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;ID&lt;/th&gt;
                  &lt;th&gt;図面No&lt;/th&gt;
                  &lt;th&gt;製品名&lt;/th&gt;
                  &lt;th&gt;工区&lt;/th&gt;
                  &lt;th&gt;鋼材&lt;/th&gt;
                  &lt;th&gt;部材&lt;/th&gt;
                  &lt;th&gt;長さ&lt;/th&gt;
                  &lt;th&gt;単重&lt;/th&gt;
                  &lt;th&gt;鉄板その他&lt;/th&gt;
                  &lt;th&gt;重量&lt;/th&gt;
                  &lt;th&gt;タグID&lt;/th&gt;
                  &lt;th&gt;ステータス&lt;/th&gt;
                  &lt;th&gt;ロケーション&lt;/th&gt;
                  &lt;th&gt;エリア&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
  
          &lt;tbody&gt;
          @foreach ($items as $item)
              &lt;tr&gt;
                  &lt;td&gt;{{$item-&gt;element_design_id}}&lt;/td&gt;ID
                  &lt;td&gt;{{$item-&gt;doc_no}}&lt;/td&gt;図面No
                  &lt;td&gt;{{$item-&gt;element_name}}&lt;/td&gt;製品名
                  &lt;td&gt;{{$item-&gt;district_name}}&lt;/td&gt;
                  &lt;td&gt;{{$item-&gt;material_name}}&lt;/td&gt;鋼材
                  &lt;td&gt;{{$item-&gt;element_size}}&lt;/td&gt;部材
                  &lt;td&gt;{{$item-&gt;element_length}}&lt;/td&gt;長さ
                  &lt;td&gt;{{$item-&gt;single_weight}}&lt;/td&gt;単重
                  &lt;td&gt;{{$item-&gt;remarks}}&lt;/td&gt;
                  &lt;td&gt;{{$item-&gt;total_weight}}&lt;/td&gt;
                  &lt;td&gt;{{$item-&gt;device_id}}&lt;/td&gt;
                  &lt;td&gt;{{$item-&gt;status_name}}&lt;/td&gt;
                  &lt;td&gt;{{$item-&gt;location_name}}&lt;/td&gt;
                  &lt;td&gt;{{$item-&gt;area_name}}&lt;/td&gt;
              &lt;/tr&gt;
          @endforeach
          &lt;/tbody&gt;
  &lt;/table&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  
  
  
  </code></pre>
  
  <p>I am using Laravel 5.7 and PHP 7.</p>
  
  <p>Please see the code above and help me.
  Thank you so much,
  BienHV</p>