5

I have following code:

$pdf = \App::make('dompdf');
$pdf->loadView('offers.pdf',compact('email','messages'));
return $pdf->stream();

pdf.blade.php:

<!doctype html>
<html class="no-js" lang="sk">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style type="text/css">
        * {
            font-family: "Arial";
        }
    </style>
</head>
<body>
Rozpočet, Voliteľné časti
</body>
</html>

PDF document looks like:

Rozpo?et,Volite?né ?asti

But I need show special characters like in pdf.blade.php file, do you have some solutions for me?

Dracontis
  • 4,184
  • 8
  • 35
  • 50
Ľuboš
  • 93
  • 2
  • 10
  • possible duplicate of [dompdf special characters](http://stackoverflow.com/questions/5136067/dompdf-special-characters) – BrianS Jun 04 '15 at 21:36
  • The only fonts you have access to by default are the core PDF fonts (which only support WIndows ANSI encoding) and the DejaVu fonts (for Unicode support in dompdf 0.6.0 or higher). Any other fonts have to be loaded in to dompdf or referenced via CSS. My answer here might be helpful: http://stackoverflow.com/a/24517882/264628 – BrianS Jun 04 '15 at 21:43

2 Answers2

0

This worked for me:

<html>

<head>
  <meta http-equiv="Content-Type" content="charset=utf-8" />
  <style type="text/css">
    * {
      font-family: "DejaVu Sans Mono", monospace;
    }
  </style>
</head>

<body>your content ćčžšđ...</body>

</html>
andreshg112
  • 582
  • 1
  • 8
  • 20
0

For Laravel 8, I solved my problem with the help of the https://github.com/mpdf/mpdf PHP package.

First of all, I've created a view template in my resources folder, "pdfview.blade.php"

<!DOCTYPE HTML>
<html lang="fa">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
    <table dir="rtl">
        <tr>
            <th>ردیف</th>
            <th>عنوان</th>
            <th>توضیحات</th>
        </tr>
        @foreach ($items as $key => $item)
            <tr style="padding: 5px">
                <td style="padding: 10px">{{ ++$key }}</td>
                <td style="background: #efefef; padding: 10px">{{ $item->title }}</td>
                <td style="padding: 10px">{{ $item->body }}</td>
            </tr>
        @endforeach
    </table>
</body>

and created a method in my controller:

public function pdfview()
{
    $items = Post::get();
    // change the root directory of fonts.
    $fontDirs = public_path() . "/fonts/MY_FONT_NAME/";
    // specify the font
    $fontData = [
        "MY_FONT_NAME" => [
            'R' => 'MY_FONT_NAME.ttf'
         ],
    ];
    $mpdf = new Mpdf([
        'fontDir' => $fontDirs,
        'fontdata' => $fontData,
        'default_font' => 'MY_FONT_NAME'
    ]);
    // render view as HTML
    $html = view('pdfview', compact('items'))->render();
    $mpdf->WriteHTML($html);
    return $mpdf->Output();
}