下载好所需字体后,
1、放入新建的 resources/fonts 文件夹中,如下:
2、配置 config/pdf.php 文件,如下:
<?php
return [
/*
* Logging
* This will log to a file in storage_path('logs/pdf.log')
* To use Laravel default logging set to default
* Comment out or set to null to disable logging
*/
'logging' => 'custom',
// ConstructorParams
'mode' => 'utf-8',
'format' => 'A4',
// 'default_font_size' => 0,注释
// 'default_font' => '',注释
'margin_left' => 15,
'margin_right' => 15,
'margin_top' => 16,
'margin_bottom' => 16,
'margin_header' => 9,
'margin_footer' => 9,
'orientation' => 'P',
/**
* Set custom temporary directory
* The default temporary directory is vendor/mpdf/mpdf/tmp
*
* @see https://mpdf.github.io/installation-setup/folders-for-temporary-files.html
* Comment the following line to keep the temporary directory
*/
'tempDir' => storage_path('app/pdf/tmp'), // absolute path
/**
* Custom Fonts
* 1) Add your custom fonts to one of the directories listed under
* 'fontDir' in which Mpdf will look for fonts
*
* 2) Define the name of the font and its configuration under the array 'fontdata'
*
* @see https://mpdf.github.io/fonts-languages/fonts-in-mpdf-7-x.html
*/
// List of Directories Containing fonts (use absolute path),注意配置自定义字体的路径正确
'font_path' => base_path('resources/fonts/'),
// Fonts Configurations,将指定路径下的字体文件正确进行配置
'font_data' => [
// font name should be lower-case and contain no spaces
'geneimonocode' => [
'R' => 'geneimonocode_regular.ttf', // regular font
'B' => 'geneimonocode_bold.ttf', // optional: bold font
],
'geneimonogothic' => [
'R' => 'geneimonogothic_regular.ttf', // regular font
'B' => 'geneimonogothic_bold.ttf', // optional: bold font
],
],
];
3、在 report.blade.php 中的正确使用方法,如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>report_photo 様式3-3</title>
<style type="text/css">
@page {
header: page-header;
footer: page-footer;
}
body,td{font-size:13px;}
{{--在此处引用 pdf.php 配置文件中设置的 geneimonocode,相当于将指定字体应用于生成的 PDF 文件 --}}
body {font-family:'geneimonocode',sans-serif;}
.gridCenter td{text-align: center}
</style>
</head>
···
</html>