At the beginning of the research, I was surprised that there was no mature scheme. Baidu found some schemes that were not compatible with Chinese.
Finally found a good library in Gayhub (Github).
The require composition of Composer is as follows:
"brainsware/php-markdown-extra-extended" : "dev-master",
"mpdf/mpdf" : "dev-master"Copy the code
Brainsware/PHP-Markdown-extra-Extended is a markdown-to-HTML library.
MPDF/MPDF is the HTML-to-Markdown library.
In fact, there are a lot of markdown to HTML, just take one of them. The main problem is that the PDF class library is not compatible with Chinese, and it is difficult to solve various fonts, or it will lead to huge PDF files.
github.com/mpdf/mpdf
mpdf.github.io/
MPDF needs to support Chinese still need to do some Settings, but super simple, directly use TTF font can be.
$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults(); $fontDirs = $defaultConfig['fontDir']; $defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults(); $fontData = $defaultFontConfig['fontdata']; $MPDF = new \ MPDF \ MPDF (['fontDir' => array_merge($fontDirs, [app_path. 'PDFFonts', // set your custom font directory]), $fontdata => $fontdata => $fontdata => $fontdata => $fontdata => $fontdata => $fontdata Followed by file name 'yaheimono' = > [' R '= >' MSYHMONO. The vera.ttf ', 'I' = > 'MSYHMONO. The vera.ttf', 'B' = > 'MSYHMONO. The vera.ttf', 'BI' = > 'MSYHMONO. The vera.ttf',]. ], 'default_font' => 'yaheimono' // set default font]); $MPDF ->useSubstitutions = true; $mpdf->backupSubsFont = array('yaheimono');Copy the code
PHP export PDF experience: doc.yurunsoft.com/YurunHttp (top right)