PHPackages                             laurentmuller/fpdf2-make-font - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. laurentmuller/fpdf2-make-font

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

laurentmuller/fpdf2-make-font
=============================

FPDF2 make font is a PHP application to generate fonts.

2.0.0(1mo ago)0503↓100%MITPHPPHP ^8.3CI passing

Since Apr 14Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/laurentmuller/fpdf2-make-font)[ Packagist](https://packagist.org/packages/laurentmuller/fpdf2-make-font)[ Docs](https://github.com/laurentmuller/fpdf2-make-font)[ RSS](/packages/laurentmuller-fpdf2-make-font/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (2)Versions (19)Used By (0)

FPDF2 Make Font
===============

[](#fpdf2-make-font)

This repository is used within [FPDF2](https://github.com/laurentmuller/fpdf2)to create font definitions.

All code is copied from the [FPDF](https://www.fpdf.org/) created by Olivier PLATHEY.

Requirements
------------

[](#requirements)

BranchPHP Versionmaster8.31.x8.2**Function:**

```
makeFont(string fontFile [, string encoding [, boolean embed [, boolean subset]]])
```

**Parameters:**

- `fontFile`: The path to the `.ttf`, `.otf` or `.pfb` file.
- `encoding`: The name of the encoding to use. The default value is `cp1252`.
- `embed`: Whether to embed the font or not. The default value is `true`.
- `subset`: Whether to subset the font or not. The default value is `true`.

The first parameter is the name of the font file. The extension must be either `.ttf`, `.otf` or `.pfb` and determines the font type. If your Type1 font is in ASCII format (`.pfa`), you can convert it to binary (`.pfb`) with the help of [Type 1 utilities](http://www.lcdf.org/~eddietwo/type/#t1utils). For Type1 fonts, the corresponding `.afm` file must be present in the same directory.

The encoding defines the association between a code (from 0 to 255) and a character. The first 128 are always the same and correspond to ASCII; the following are variable. Encodings are stored in `.map` files. The available encoding ones are:

- cp1250 (Central Europe)
- cp1251 (Cyrillic)
- cp1252 (Western Europe)
- cp1253 (Greek)
- cp1254 (Turkish)
- cp1255 (Hebrew)
- cp1257 (Baltic)
- cp1258 (Vietnamese)
- cp874 (Thai)
- ISO-8859-1 (Western Europe)
- ISO-8859-2 (Central Europe)
- ISO-8859-4 (Baltic)
- ISO-8859-5 (Cyrillic)
- ISO-8859-7 (Greek)
- ISO-8859-9 (Turkish)
- ISO-8859-11 (Thai)
- ISO-8859-15 (Western Europe)
- ISO-8859-16 (Central Europe)
- KOI8-R (Russian)
- KOI8-U (Ukrainian)

Of course, the font must contain the characters corresponding to the selected encoding.

The third parameter indicates whether the font should be embedded in the PDF or not. When a font is not embedded, it is searched in the system. The advantage is that the PDF file is smaller; but if it is not available, then a substitution font is used. So you should ensure that the required font is installed on the client systems. Embedding is the recommended option to guarantee a correct rendering.

The last parameter indicates whether sub-setting should be used, that is to say, whether only the characters from the selected encoding should be kept in the embedded font. As a result, the size of the PDF file can be greatly reduced, especially if the original font was big.

After you have called the function (create a new file for this and include `make.php`), a `.json` file is created, with the same name as the font file. You may rename it if you wish. If the case of embedding, the font file is compressed and gives a second file with `.z` as extension except if the compression function is not available (it requires Zlib). You may rename it too, but in this case you have to change the variable `$file` in the `.json` file accordingly.

**Example:**

```
require('src/makeFont.php');

makeFont('C:\\Windows\\Fonts\\comic.ttf','cp1252');
```

Which gives the files `comic.json` and `comic.z`.

Then copy the generated files to the font directory. If the font file could not be compressed, copy it directly instead of the `.z` version.

Another way to call `makeFont()` is through the command line:

```
php src\makeFont.php C:\Windows\Fonts\comic.ttf cp1252
```

**Declaration of the font in the script:**

The second step is straightforward. You only need to call the `addFont()`method:

```
$pdf->addFont('Comic', PdfFontStyle::REGULAR, 'comic.json');
```

And the font is now available (in regular and underlined styles), usable like the others. If we had worked with Comic Sans MS Bold (`comicbd.ttf`), we would have written:

```
$pdf->addFont('Comic', PdfFontStyle::BOLD, 'comicbd.json');
```

**Full Example:**

Now let's see a complete example. We will use the [Ceviche One](https://fonts.google.com/specimen/Ceviche+One) font. The first step is the generation of the font files:

```
require('src/makeFont.php');

makeFont('CevicheOne-Regular.ttf', 'cp1252');
```

The script produces the following output:

- Font file compressed: `CevicheOne-Regular.z`.
- Font definition file generated: `CevicheOne-Regular.json`.

Alternatively, we could have used the command line:

```
php src\makeFont.php CevicheOne-Regular.ttf cp1252
```

We can now copy the two generated files to the font directory and write the script:

```
use fpdf\Enums\PdfFontStyle;
use fpdf\PdfDocument;

$pdf = new PdfDocument();
$pdf->addFont('CevicheOne', PdfFontStyle::REGULAR, 'CevicheOne-Regular.json');
$pdf->addPage();
$pdf->setFont('CevicheOne', PdfFontStyle::REGULAR, 45);
$pdf->write(10, 'Enjoy new fonts with FPDF!');
$pdf->output();
```

Symfony
-------

[](#symfony)

A [Symfony application](https://github.com/laurentmuller/fpdf2-make-font-ui) has been created to generate fonts.

[![User Interface](images/ui_light_wide.png)](images/ui_light_wide.png)

Code Quality
------------

[](#code-quality)

[![SymfonyInsight](https://camo.githubusercontent.com/a942d2fcc6e46a672e4796e2f95c9cecc9669a8af0cd5233d3bb77ec1996e2ad/68747470733a2f2f696e73696768742e73796d666f6e792e636f6d2f70726f6a656374732f37663531353434662d646661332d343132332d616564322d3963396463386234323737662f6d696e692e737667)](https://insight.symfony.com/projects/7f51544f-dfa3-4123-aed2-9c9dc8b4277f)[![Codacy](https://camo.githubusercontent.com/7532235f9ab6d71291c2f5531a49e554fd7d6c1626ea21134b961a44578cec34/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3465653636393834396439663434323261623537623063313435376564383261)](https://app.codacy.com/gh/laurentmuller/fpdf2-make-font/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)[![PHP-Stan](https://camo.githubusercontent.com/daf74d517e9a2379b58014fee6bd7156bed21c42e2a40186a5b404f4b64f5c98/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c25323031302d627269676874677265656e2e7376673f7374796c653d666c6174266c6f676f3d706870)](https://phpstan.org/blog/find-bugs-in-your-code-without-writing-tests)[![CodeFactor](https://camo.githubusercontent.com/04a3f30230cda5b4b2132753d20602b75afefce93d221db3aa69b4bb59d83a9b/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f6c617572656e746d756c6c65722f66706466322d6d616b652d666f6e742f6261646765)](https://www.codefactor.io/repository/github/laurentmuller/fpdf2-make-font)[![Codecov](https://camo.githubusercontent.com/f8eb7ba1e81fb13f4c76e9ff6c447344c6033dfab44ec8bb51bab49411c18d9b/68747470733a2f2f636f6465636f762e696f2f67682f6c617572656e746d756c6c65722f66706466322d6d616b652d666f6e742f67726170682f62616467652e7376673f746f6b656e3d534e5a36444a3857364e)](https://codecov.io/gh/laurentmuller/fpdf2-make-font)

Actions
-------

[](#actions)

[![PHP-CS-Fixer](https://github.com/laurentmuller/fpdf2-make-font/actions/workflows/php-cs-fixer.yaml/badge.svg)](https://github.com/laurentmuller/fpdf2-make-font/actions/workflows/php-cs-fixer.yaml)[![PHPStan](https://github.com/laurentmuller/fpdf2-make-font/actions/workflows/php_stan.yaml/badge.svg)](https://github.com/laurentmuller/fpdf2-make-font/actions/workflows/php_stan.yaml)[![PHPUnit](https://github.com/laurentmuller/fpdf2-make-font/actions/workflows/php_unit.yaml/badge.svg)](https://github.com/laurentmuller/fpdf2-make-font/actions/workflows/php_unit.yaml)[![Rector](https://github.com/laurentmuller/fpdf2-make-font/actions/workflows/rector.yaml/badge.svg)](https://github.com/laurentmuller/fpdf2-make-font/actions/workflows/rector.yaml)[![Lint](https://github.com/laurentmuller/fpdf2-make-font/actions/workflows/lint.yaml/badge.svg)](https://github.com/laurentmuller/fpdf2-make-font/actions/workflows/lint.yaml)[![StyleCI](https://camo.githubusercontent.com/4eaf8a449b297f61c2a30ca4b1db856029876b6149b973ebdd7b0157966dc79a/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3936333330363632382f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/963306628?branch=master)

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance91

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~17 days

Recently: every ~29 days

Total

18

Last Release

44d ago

Major Versions

1.1.7 → 2.0.02026-02-09

PHP version history (2 changes)1.0.0PHP ^8.2

2.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/dab4ea3de121409abc146b42eecc364144bbbdc197148e154cdecbfa0651ad87?d=identicon)[laurentmuller](/maintainers/laurentmuller)

---

Top Contributors

[![laurentmuller](https://avatars.githubusercontent.com/u/4330059?v=4)](https://github.com/laurentmuller "laurentmuller (61 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/laurentmuller-fpdf2-make-font/health.svg)

```
[![Health](https://phpackages.com/badges/laurentmuller-fpdf2-make-font/health.svg)](https://phpackages.com/packages/laurentmuller-fpdf2-make-font)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
