{"id":14983908,"url":"https://github.com/jbtronics/dompdf-font-loader-bundle","last_synced_at":"2025-04-10T19:41:36.050Z","repository":{"id":177957108,"uuid":"661145482","full_name":"jbtronics/dompdf-font-loader-bundle","owner":"jbtronics","description":"A symfony bundle to easily load custom fonts for dompdf (on cache warming)","archived":false,"fork":false,"pushed_at":"2025-02-07T23:22:02.000Z","size":19,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T17:21:14.998Z","etag":null,"topics":["dompdf","fonts","symfony","symfony-bundle"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jbtronics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-01T23:46:40.000Z","updated_at":"2025-02-07T23:21:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"e6cbf47c-f4ec-4479-8405-4d3d6168201b","html_url":"https://github.com/jbtronics/dompdf-font-loader-bundle","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"de3a2982e626144bc543119585ed46dc4c884bea"},"previous_names":["jbtronics/dompdf-font-loader-bundle"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbtronics%2Fdompdf-font-loader-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbtronics%2Fdompdf-font-loader-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbtronics%2Fdompdf-font-loader-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbtronics%2Fdompdf-font-loader-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jbtronics","download_url":"https://codeload.github.com/jbtronics/dompdf-font-loader-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248281415,"owners_count":21077423,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dompdf","fonts","symfony","symfony-bundle"],"created_at":"2024-09-24T14:08:09.633Z","updated_at":"2025-04-10T19:41:36.027Z","avatar_url":"https://github.com/jbtronics.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Font loader for dompdf Bundle\n\nThis bundle provides a simple way to load/install fonts of your choice for the [dompdf](https://github.com/dompdf/dompdf) library in a symfony project.\nThis bundle offers functionality to load font families programmatically or automatically on cache warmup.\nYou can specify each font family with a name and a path to the font files or you let the bundle autodiscover all fonts in a directory.\n\n## Feautures\n* Services for easy installation of font families\n* Configure font families in your config files, which will be loaded automatically on cache warmup\n* Autodiscover all fonts in configured directories\n\n## Requirements\n* Symfony 6\n* PHP 8.1 or later\n\n## Installation\n1. Install the bundle `composer require jbtronics/dompdf-font-loader-bundle`\n2. Enable the bundle in your `config/bundles.php` (normally done by Symfony flex automatically)\n3. Put the font TTF files you want to use in a directory the webserver can access (preferably somewhere in your project folder)\n4. Add a config file `config/packages/jbtronics_dompdf_font_loader.yaml`, with the content described below (and changed according to your need)\n\n## Configuration\n\n```yaml\ndompdf_font_loader:\n  \n  # Set this to true to enable the automatic font loading on cache warmup, without it you have to load the fonts\n  # manually via the ConfiguredFontsInstaller service\n  auto_install: true\n\n  # You can specify font families here manually\n  fonts:\n    my_font: # The name of the font family (used to access it in dompdf later)\n      # A font family consists of up to four font files (normal, bold, italic, bold_italic)\n      normal: \"%kernel.project_dir%/assets/fonts/my_font.ttf\"\n      bold: \"%kernel.project_dir%/assets/fonts/my_font_bold.ttf\"\n      italic: \"%kernel.project_dir%/assets/fonts/my_font_italic.ttf\"\n      bold_italic: \"%kernel.project_dir%/assets/fonts/my_font_bold_italic.ttf\"\n      \n    # But only the normal font file is required, the others can be omitted\n    unifont:\n      normal: \"%kernel.project_dir%/assets/fonts/unifont.ttf\"\n\n  # Autodiscover allows you to specify directories, where all fonts will be loaded automatically\n  autodiscovery:\n    # Each of this directory will be scanned for font files \n    paths:\n      - \"%kernel.project_dir%/assets/fonts\"\n      - \"%kernel.project_dir%/vendor/fonts/package/ttfs\"\n    exclude_patterns:\n      # You can exclude certain patterns from the autodiscovery if you want\n       - \"exclude_this_font.ttf\"\n```\n\nThe fonts and autodiscovery keys are both optional, but at least one of them is required to load fonts.\n\n## Usage\n\nWhen you have enabled the `auto_install` option, you do not have to do anything else, the fonts will be loaded automatically on cache warmup (when `php bin/console cache:clear` is run).\nThe bundle will copy the font files to the dompdf font directory, create font metrics and register them in the dompdf library.\n\n### Autodiscovery\nThe autodiscovery mechanism will scan the configured directories for TTF files and register them as font families with the name of the font file. \nIt also tries to detect the type of the font based on a suffix: `_bold` or `_b` will be detected as bold fonts, `_italic`, `_i` as italic fonts, and `_bold_italic` or `_bi` as bold italic.\nSo the `my_font_bold.ttf` will be registered as bold font of the `my_font` family and so on, while `my_font.ttf` will be registered as normal font of the `my_font` family.\n\nIn principle dompdf should be able to use OTF files as well, however in my tests it did not work, so autodiscovery only detects TTF files by default. You can change the detected file types via the `autodiscovery.file_pattern` option.\n\n### Specify DOMPDF font location\nDompdf has its own font directory, where it stores the font files and metrics. This is configured on a per instance basis on a dompdf object with the `set_option('fontDir', $path)` method.\nTo specify the font directory for the dompdf instance used by this bundle, you must decorate the `DompdfFactoryInterface` and configure the object in the `create()` method:\n\n```php\n#[AsDecorator(decorates: DompdfFactoryInterface::class)]\nclass MyDompdfFactory implements DompdfFactoryInterface\n{\n    public function create(): Dompdf\n    {\n        return new Dompdf(['fontDir' =\u003e '%kernel.project_dir%/var/dompdf/fonts']);\n    }\n}\n```\n\n### Manual font loading/installation\nThis bundle offers the `DompdfFontLoader` service, which can be used to install font families manually.\nYou can either install a single font family with the `installFontFamily()` method or install all found fonts in a folder with the `autodiscoverAndInstallFonts()` method.\n\n## License\nThis bundle is licensed under the MIT license. See [LICENSE](LICENSE) for details.\n\n## Credits\n* [dompdf](https://github.com/dompdf/dompdf)\n* This bundle was inspired by the offical dompdf util script [load_font.php](https://github.com/dompdf/utils/blob/master/load_font.php)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbtronics%2Fdompdf-font-loader-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjbtronics%2Fdompdf-font-loader-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbtronics%2Fdompdf-font-loader-bundle/lists"}