Skip to content

Commit

Permalink
bugfix 部分中文字体乱码,一般是中文后面跟着英文机会出现
Browse files Browse the repository at this point in the history
  • Loading branch information
mylxsw committed May 14, 2019
1 parent 526164f commit 3a419cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
13 changes: 8 additions & 5 deletions app/Http/Controllers/BatchExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace App\Http\Controllers;


use App\Policies\ProjectPolicy;
use App\Repositories\Document;
use App\Repositories\Project;
Expand Down Expand Up @@ -167,6 +166,8 @@ private function exportPDF(array $navigators, Project $project, Collection $docu
'mode' => 'utf-8',
'tempDir' => sys_get_temp_dir(),
'defaultfooterline' => false,
'useSubstitutions' => true,
'backupSubsFont' => ['dejavusanscondensed', 'arialunicodems', 'sun-exta'],
]);

$mpdf->allow_charset_conversion = true;
Expand All @@ -186,7 +187,8 @@ private function exportPDF(array $navigators, Project $project, Collection $docu
$mpdf->WriteHTML($header);

$pageNo = 1;
$this->traverseNavigators($navigators,
$this->traverseNavigators(
$navigators,
function ($id, array $parents) use ($documents, $mpdf, &$pageNo) {
if ($pageNo > 1) {
$mpdf->AddPage();
Expand Down Expand Up @@ -225,7 +227,9 @@ function ($id, array $parents) use ($documents, $mpdf, &$pageNo) {
}

$pageNo++;
}, []);
},
[]
);

$mpdf->Output();
}
Expand All @@ -250,7 +254,6 @@ private function traverseNavigators(array $navigators, \Closure $callback, array
}
}


/**
* 检查是否用户有导出权限
*
Expand All @@ -270,4 +273,4 @@ private function canExport($projectId)

return $project;
}
}
}
15 changes: 8 additions & 7 deletions app/Http/Controllers/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

class ExportController extends Controller
{

/**
* 直接将内容导出为下载文件
*
Expand Down Expand Up @@ -45,15 +44,19 @@ public function pdf(Request $request, $type)
$author = $request->input('author');

$mpdf = new Mpdf([
'mode' => 'utf-8',
'tempDir' => sys_get_temp_dir()
'mode' => 'utf-8',
'tempDir' => sys_get_temp_dir(),
'useSubstitutions' => true,
'backupSubsFont' => ['dejavusanscondensed', 'arialunicodems', 'sun-exta'],
]);

$mpdf->SetFooter('{PAGENO} / {nbpg}');
$mpdf->SetTitle($title);

$mpdf->allow_charset_conversion = true;
$mpdf->useAdobeCJK = true;
$mpdf->autoLangToFont = true;
$mpdf->autoScriptToLang = true;
$mpdf->title = $title;
$mpdf->author = $author ?? \Auth::user()->name ?? 'wizard';

$header = '<link href="/assets/css/normalize.css" rel="stylesheet">';
Expand All @@ -68,7 +71,6 @@ public function pdf(Request $request, $type)
break;
}


$header .= '<link href="/assets/css/style.css" rel="stylesheet">';
$header .= '<link href="/assets/css/pdf.css" rel="stylesheet">';
$mpdf->WriteHTML($header);
Expand All @@ -91,5 +93,4 @@ public function pdf(Request $request, $type)

$mpdf->Output();
}

}
}

0 comments on commit 3a419cf

Please sign in to comment.