定制 aklump/dompdf-fonts 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

aklump/dompdf-fonts

最新稳定版本:0.0.18

Composer 安装命令:

composer require aklump/dompdf-fonts

包简介

Simplify the usage of TrueType fonts with DomPDF.

README 文档

README

I wrote this project to simplify using custom fonts with DOMPDF.

Installation

  1. composer require aklump/dompdf-fonts
  2. Create a directory in your project to hold the source fonts and the configuration file.
  3. Copy the config file found in vendor/aklump/dompdf-fonts/dompdf-fonts.config.dist.yml to the font folder as dompdf-fonts.config.yml.

In a Drupal Module

Installation

  1. cd my_module
  2. Install as a dev requirement: composer require --dev aklump/dompdf-fonts
  3. mkdir fonts
  4. cp vendor/aklump/dompdf-fonts/dompdf-fonts.config.dist.yml fonts/dompdf-fonts.config.yml

Importing

  1. Copy source font into fonts/.
  2. ./vendor/bin/import.php fonts/dompdf-fonts.config.yml

For example:

composer require aklump/dompdf-fonts
mkdir fonts
cp vendor/aklump/dompdf-fonts/dompdf-fonts.config.dist.yml fonts/dompdf-fonts.config.yml

Get the .ttf font files

  1. Download one or more font families, say from https://fonts.google.com
  2. For use with DomPDF you only need the .ttf versions. Copy those to your source directory. In the examples shown below, that directory is ./fonts.
  3. You will need up to four versions of the font: normal, bold, italic and bold italic.

Example file tree.

.
├── dist
│   └── dompdf_fonts
│       ├── Merriweather--bold-italic.ttf
│       ├── Merriweather--bold-italic.ufm
│       ├── Merriweather--bold.ttf
│       ├── Merriweather--bold.ufm
│       ├── Merriweather--italic.ttf
│       ├── Merriweather--italic.ufm
│       ├── Merriweather--normal.ttf
│       ├── Merriweather--normal.ufm
│       ├── _style.scss
│       └── installed-fonts.json
└── fonts
    ├── dompdf-fonts.config.yml
    ├── Merriweather--bold-italic.ttf
    ├── Merriweather--bold.ttf
    ├── Merriweather--italic.ttf
    ├── Merriweather--normal.ttf
    └── dompdf
        └── import.php

Set the import configuration

  1. dompdf-fonts.config.yml should have been copied from dompdf-fonts.config.dist.yml when you installed this, if not you must manually do so now.
  2. Update dompdf-fonts.config.yml as appropriate. All paths are relative to dompdf-fonts.config.yml's parent directory.

File: _dompdf-fonts.config.yml

sources:
  - ../Merriweather*.ttf
output: ../../dist/dompdf_fonts/

Run the importer

  1. Run php vendor/bin/import.php path/to/dompdf-fonts.config.yml to process your fonts.
  2. Inspect to make sure your output directory contains the necessary files.

Use with Dompdf instances

  1. Set the fonts directory to match output.path on every new DOMPDF instance in your code. This is an example from a Drupal 9 module.
$options = new \Dompdf\Options();

// Determine the configuration directory by reading the import config.
$fonts_base_path = \Drupal::service('extension.list.module')
    ->getPath('my_module') . '/fonts';
$fonts_config = \Symfony\Component\Yaml\Yaml::parseFile($fonts_base_path . '/dompdf-fonts.config.yml');
$fonts_dir = realpath($fonts_base_path . '/' . $fonts_config['output']['path']);
$options->setFontDir($fonts_dir);

$dompdf = new \Dompdf\Dompdf($options);

Use with HTML markup

  1. To see your font in the browser you must import the SCSS partial. When only rendering PDFs, DOMPDF does not use _style.scss.

File: my_module/scss/_pdf.scss

@import "../dist/dompdf_fonts/style";

@mixin pdf_font_serif {
  font-family: Merriweather, Georgia, Times, "Times New Roman", serif;
}

h1 {
  @include pdf_font_serif;
}

Resource Links

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2022-10-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固