laravel-dompdf
laravel-dompdf copied to clipboard
Displaying Chinese Characters
Hello everyone, I intend to generate a PDF in Chinese. But the Chinese characters become "?" in the PDF (English characters are fine.)
Here is the solution I have tried: 1.1. Added simhei.ttf in fonts directory (ALSO tried it in public/fonts) 1.2. And added the CSS below in my blade.php. But it is not working
Is there any way I could solve this problem?
This is the current output:
This package is only a Laravel wrapper for Dompdf HTML to PDF Converter,
that is specified in the first line of the README.md
This is how I did it, having read a number of the issues on the Dompdf tracker. Two observations:
- The font you are using matters greatly, so if it's not working, check the font you are importing.
- There is a bug in this library with setting options, this is what I have a convoluted approach below. If you don't set isFontSubsettingEnabled equal to true, your PDF size will be huge. By adding it, I went from 8mb to less than 500kb
`<?php
use Barryvdh\DomPDF\Facade\Pdf; use Illuminate\Support\Facades\Storage;
//Get the default settings $options = PDF::getDomPDF()->getOptions(); $options->set('isFontSubsettingEnabled', true);
$pdf = PDF::setPaper('a4', 'landscape'); //Set the options, if we use the included function, the defaults are overwritten and this leads to weird behaviour. $pdf->getDomPDF()->setOptions($options); $pdf->loadView('pdf.show', ['attributes' => 'stuff']);
//Store to S3 (or output as you wish) Storage::put('my-file.pdf', $pdf->output());
//pdf.show View
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/dompdf/dompdf instead. When having doubts, please try to reproduce the issue with just dompdf. If you believe this is an actual issue with the latest version of laravel-dompdf, please reply to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.