承接 appotter/mpdf 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

appotter/mpdf

Composer 安装命令:

composer require appotter/mpdf

包简介

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

README 文档

README

mPDF is a PHP class which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF (see CREDITS), with a number of enhancements. mPDF was written by Ian Back and is released under the GNU GPL v2 licence.

Releases

  • [20170707] Update jpgraph with a new version (4.0.2)

Installation

  • Download the .zip file and unzip it

  • Create a folder e.g. /mpdf on your server

  • Upload all of the files to the server, maintaining the folders as they are

  • Ensure that you have write permissions set (CHMOD 6xx or 7xx) for the following folders:

    /ttfontdata/ - used to cache font data; improves performance a lot

    /tmp/ - used for some images and ProgressBar

    /graph_cache/ - if you are using JpGraph in conjunction with mPDF

To test the installation, point your browser to the basic example file:

[path_to_mpdf_folder]/mpdf/examples/example01_basic.php

If you wish to define a different folder for temporary files rather than /tmp/ see the note on Folder for temporary files in the section on Installation & Setup in the manual.

If you have problems, please read the section on troubleshooting in the manual.

Fonts

Let us refer to font names in 2 ways:

  1. "CSS font-family name" - mPDF is designed primarily to read HTML and CSS. This is the name used in CSS e.g.

    <p style="font-family: 'Trebuchet MS';">

  2. "mPDF font-family name" - the name used internally to process fonts. This could be anything you like, but by default mPDF will convert CSS font-family names by removing any spaces and changing to lowercase. Reading the name above, mPDF will look for a "mPDF font-family name" of:

    'trebuchetms'

The configurable values referred to below are set in the config_fonts.php file.

When parsing HTML/CSS, mPDF will read the CSS font-family name (e.g. 'Trebuchet MS') and convert by removing any spaces and changing to lowercase, to look for a mPDF font-family name (trebuchetms).

Next it will look for a translation (if set) in config_font.php e.g.:

$this->fonttrans = array(
    'trebuchetms' => 'trebuchet'
)

Now the mPDF font-family name to be used is 'trebuchet'

If you wish to make this font available, you need to specify the Truetype .ttf font files for each variant. These should be defined in config_font.php in the array:

$this->fontdata = array(
    "trebuchet" => array(
	    'R' => "trebuc.ttf",
	    'B' => "trebucbd.ttf",
	    'I' => "trebucit.ttf",
	    'BI' => "trebucbi.ttf",
	    )
)

This is the array which determines whether a font is available to mPDF. Each font-family must have a Regular ['R'] file defined - the others (bold, italic, bold-italic) are optional.

mPDF will try to load the font-file. If you have defined _MPDF_SYSTEM_TTFONTS at the top of the config_fonts.php file, it will first look for the font-file there. This is useful if you are running mPDF on a computer which already has a folder with TTF fonts in (e.g. on Windows)

If the font-file is not there, or _MPDF_SYSTEM_TTFONTS is not defined, mPDF will look in the folder

/[your_path_to_mpdf]/ttfonts/

Note that the font-file names are case-sensitive and can contain capitals.

If the folder /ttfontdata/ is writeable (CHMOD 644 or 755), mPDF will save files there which it can re-use next time it accesses a particular font. This will significantly improve processing time and is strongly recommended.

mPDF should be able to read most TrueType Unicode font files with a .ttf extension. Truetype fonts with .otf extension that are OpenType also work OK. TrueType collections (.ttc) will also work if they contain TrueType Unicode fonts.

Character substitution

Most people will have access to a Pan-Unicode font with most Unicode characters in it such as Arial Unicode MS. Set:

$this->backupSubsFont = array('arialunicodems');

at the top of the config_fonts.php file to use this font when substituting any characters not found in the specific font being used.

Example: You can set:

$mpdf->useSubstitutions = true;

at runtime, or

$this->useSubstitutions = true;

in the config.php file

This text contains a Thai character ม which does not exist in the Comic Sans MS font file

When useSubstitutions is true, mPDF will try to find substitutions for any missing characters:

  1. firstly looks if the character is available in the inbuilt Symbols or ZapfDingbats fonts;
  2. [If defined] looks in each of the the font(s) set by $this->backupSubsFont array

NB There is an increase in processing time when using substitutions, and even more so if a backupSubsFont is defined.

Controlling mPDF mode

The first parameter of new mPDF('') works as follows:

  • new mPDF('c') - forces mPDF to only use the built-in [c]ore Adobe fonts (Helvetica, Times etc)

  • new mPDF('') - default - font subsetting behaviour is determined by the configurable variables $this->maxTTFFilesize and $this->percentSubset (see below)

    Default values are set so that:

    1. Very large font files are always subset
    2. Fonts are embedded as subsets if < 30% of the characters are used
  • new mPDF('..+aCJK')

    new mPDF('+aCJK')

    new mPDF('..-aCJK')

    new mPDF('-aCJK')

    Used optionally together with a language or language/country code, +aCJK will force mPDF to use the Adobe non-embedded CJK fonts when a passage is marked with e.g. "lang: ja"

    This can be used at runtime to override the value set for $mpdf->useAdobeCJK in config.php

    Use in conjunction with settings in config_cp.php

For backwards compatibility, new mPDF('-s') and new mPDF('s') will force subsetting by setting

$this->percentSubset=100

new mPDF('utf-8-s') and new mPDF('ar-s') are also recognised

Configuration variables changed

Configuration variables are documented in the on-line manual.

Font folders

If you wish to define your own font file folders (perhaps to share), you can define the 2 constants in your script before including the mpdf.php script e.g.:

define('_MPDF_TTFONTPATH','your_path/ttfonts/');
define('_MPDF_TTFONTDATAPATH','your_path/ttfontdata/'); 	// should be writeable

appotter/mpdf 适用场景与选型建议

appotter/mpdf 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.62k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2014 年 08 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「pdf」 「utf-8」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 appotter/mpdf 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 appotter/mpdf 我们能提供哪些服务?
定制开发 / 二次开发

基于 appotter/mpdf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.62k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2014-08-11