Laravel 中 PDF 文件中设置自定义字体

下载好所需字体后,
1、放入新建的 resources/fonts 文件夹中,如下:


image.png

2、配置 config/pdf.php 文件,如下:

 '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 中的正确使用方法,如下:




    
    report_photo 様式3-3
    

···

你可能感兴趣的:(Laravel 中 PDF 文件中设置自定义字体)