Skip to content

wuchuhengtools/generate_pdf_with_php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

1 使用说明

1.1 安装依赖

$ composer install

1.2 导入字体

字体文件位于public/assets/fonts;

$ php vendor/tecnickcom/tcpdf/tools/tcpdf_addfont.php -i src/public/assets/fonts/MicrosoftYaHei.ttf   

导入成功后,会在vendor/tecnickcom/tcpdf/fonts/生相关的字体文件名,然后就可以使用字体了

1.3 生成pdf

$ php src/main.php

然后在src/runtime/的目录下就有生成好的文件了。

1 Q&A

1.2 中文字体乱码问题

1.2.1 安装微软字体

下载完依赖后,进行字体安装

$  php vendor/tecnickcom/tcpdf/tools/tcpdf_addfont.php -i src/public/assets/fonts/MicrosoftYaHei.ttf   

>>> Converting fonts for TCPDF:
*** Output dir set to /www/vendor/tecnickcom/tcpdf/fonts/
+++ OK   : /www/src/public/assets/fonts/MicrosoftYaHei.ttf added as microsoftyahei
>>> Process successfully completed!

然后就可以直接在代码中使用了

$this->setFont('microsoftyahei');

1.3 需要哪些扩展

  • gd
  • zip

2 如何导入*PingFang-SC-Light`字体?

$  php vendor/tecnickcom/tcpdf/tools/tcpdf_addfont.php -i src/public/assets/fonts/PingFang-SC-Light.ttf  

>>> Converting fonts for TCPDF:
*** Output dir set to /www/vendor/tecnickcom/tcpdf/fonts/
+++ OK   : /www/src/public/assets/fonts/PingFang-SC-Light.ttf added as pingfangsclight
>>> Process successfully completed!

然后在TCPDF中修改要使用的字体

main.php

<?php

// ...

class MYPDF extends TCPDF {
    public $_sideMargin= 10;

    // 表格边框style
    public  $tableBorder = ['LTRB' => array('width' => 0.2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => [189, 189, 189])];

    // 微软雅黑字体: 这个手动导入,详细说明看README.md
    public $font= 'pingfangsclight';
    // ...
    }

字体pingfangSCLight来源 github.com/zongren/font

字体github.com/adobe-fonts/source-han-sans/releases来源

下载字体后是ttc格式,然后在字体转换网站进行转为ttf,并选择其中需要的ttf下载下来使用

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors