PHPackages                             tekintian/dompdf - 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. [PDF &amp; Document Generation](/categories/documents)
4. /
5. tekintian/dompdf

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

tekintian/dompdf
================

默认支持中文的dompdf, HTML转PDF工具类, DOMPDF is a CSS 2.1 compliant HTML to PDF converter

v2.0.4(2y ago)2173[1 issues](https://github.com/tekintian/dompdf/issues)LGPL-2.1PHPPHP ^7.1 || ^8.0

Since Feb 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/tekintian/dompdf)[ Packagist](https://packagist.org/packages/tekintian/dompdf)[ Docs](https://gitee.com/tekintian/dompdf)[ RSS](/packages/tekintian-dompdf/feed)WikiDiscussions cn Synced 1mo ago

READMEChangelogDependencies (7)Versions (28)Used By (0)

Dompdf 中文版
==========

[](#dompdf-中文版)

本项目为Dompdf的默认中文支持版本.

官方默认不支持中文,要支持中文需要一堆的设置, 太过麻烦,所以直接适配了这个默认支持中文的版本.

加载后默认支持中文,不需要任何配置.

默认中文字体: hyqh 汉仪旗黑 大小为 2.1M

使用示例
----

[](#使用示例)

安装依赖

```
composer require tekintian/dompdf
```

- 默认使用中文字体

```
use Dompdf\Dompdf;

 //初始化Dompdf对象
$dompdf = new Dompdf();

//创建HTML内容
$html = '你好Dompdf!我默认使用的是中文字体';
$dompdf->loadHtml($html);

$dompdf->loadHtml($html);

//Setup the paper size and orientation
// $dompdf->setPaper('A4', 'landscape');

//将html转为PDF
$dompdf->render();

//Output the generated PDF to Browser
$pdfname = '你好PDF.pdf';

//下载生成的pdf文件
//$dompdf->stream($pdfname);

//将生成的pdf保存到服务器
file_put_contents($pdfname, $dompdf->output());

//将生成的pdf文件渲染到页面
// $dompdf->stream($pdfname, [
//     'compress' => 0,
//     'Attachment' => 0
// ]);
```

自行添加其他中文字体
----------

[](#自行添加其他中文字体)

```
# 将 load_font.php 拷贝到项目根目录(和vendor同级目录)
cp vendor/tekintian/dompdf/load_font.php ./

# 安装字体到库中
php ./load_font.php "字体名称" "字体路径.ttf"
```

### 使用中文字体

[](#使用中文字体)

在需要进行pdf转换的HTML中使用中文字体的方式与普通的HTML相同，可以是内联样式，也可以使用在style标签中。

```
手动指定中文字体
```

技术交流QQ:932256355

**Dompdf is an HTML to PDF converter**

At its heart, dompdf is (mostly) a [CSS 2.1](http://www.w3.org/TR/CSS2/) compliant HTML layout and rendering engine written in PHP. It is a style-driven renderer: it will download and read external stylesheets, inline style tags, and the style attributes of individual HTML elements. It also supports most presentational HTML attributes.

*This document applies to the latest stable code which may not reflect the current release. For released code please [navigate to the appropriate tag](https://github.com/dompdf/dompdf/tags).*

---

**Check out the [demo](http://eclecticgeek.com/dompdf/debug.php) and ask any question on [StackOverflow](https://stackoverflow.com/questions/tagged/dompdf) or in [Discussions](https://github.com/dompdf/dompdf/discussions).**

Follow us on [![Twitter](https://camo.githubusercontent.com/a48223ec1e9d088ad8d71cd6b9a63a3904b3c5f35d63fba3873ca3e55f135eef/687474703a2f2f747769747465722d6261646765732e73332e616d617a6f6e6177732e636f6d2f747769747465722d612e706e67)](http://www.twitter.com/dompdf).

---

Features
--------

[](#features)

- Handles most CSS 2.1 and a few CSS3 properties, including @import, @media &amp; @page rules
- Supports most presentational HTML 4.0 attributes
- Supports external stylesheets, either local or through http/ftp (via fopen-wrappers)
- Supports complex tables, including row &amp; column spans, separate &amp; collapsed border models, individual cell styling
- Image support (gif, png (8, 24 and 32 bit with alpha channel), bmp &amp; jpeg)
- No dependencies on external PDF libraries, thanks to the R&amp;OS PDF class
- Inline PHP support
- Basic SVG support (see "Limitations" below)

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

[](#requirements)

- PHP version 7.1 or higher
- DOM extension
- MBString extension
- php-font-lib
- php-svg-lib

Note that some required dependencies may have further dependencies (notably php-svg-lib requires sabberworm/php-css-parser).

### Recommendations

[](#recommendations)

- OPcache (OPcache, XCache, APC, etc.): improves performance
- GD (for image processing)
- IMagick or GMagick extension: improves image processing performance

Visit the wiki for more information:

About Fonts &amp; Character Encoding
------------------------------------

[](#about-fonts--character-encoding)

PDF documents internally support the following fonts: Helvetica, Times-Roman, Courier, Zapf-Dingbats, &amp; Symbol. These fonts only support Windows ANSI encoding. In order for a PDF to display characters that are not available in Windows ANSI, you must supply an external font. Dompdf will embed any referenced font in the PDF so long as it has been pre-loaded or is accessible to dompdf and reference in CSS @font-face rules. See the [font overview](https://github.com/dompdf/dompdf/wiki/About-Fonts-and-Character-Encoding)for more information on how to use fonts.

The [DejaVu TrueType fonts](https://dejavu-fonts.github.io/) have been pre-installed to give dompdf decent Unicode character coverage by default. To use the DejaVu fonts reference the font in your stylesheet, e.g. `body { font-family: DejaVu Sans; }` (for DejaVu Sans). The following DejaVu 2.34 fonts are available: DejaVu Sans, DejaVu Serif, and DejaVu Sans Mono.

Easy Installation
-----------------

[](#easy-installation)

### Install with composer

[](#install-with-composer)

To install with [Composer](https://getcomposer.org/), simply require the latest version of this package.

```
composer require dompdf/dompdf
```

Make sure that the autoload file from Composer is loaded.

```
// somewhere early in your project's loading, require the Composer autoloader
// see: http://getcomposer.org/doc/00-intro.md
require 'vendor/autoload.php';
```

### Download and install

[](#download-and-install)

Download a packaged archive of dompdf and extract it into the directory where dompdf will reside

- You can download stable copies of dompdf from
- Or download a nightly (the latest, unreleased code) from

Use the packaged release autoloader to load dompdf, libraries, and helper functions in your PHP:

```
// include autoloader
require_once 'dompdf/autoload.inc.php';
```

Note: packaged releases are named according using semantic versioning (*dompdf\_MAJOR-MINOR-PATCH.zip*). So the 1.0.0 release would be dompdf\_1-0-0.zip. This is the only download that includes the autoloader for Dompdf and all its dependencies.

### Install with git

[](#install-with-git)

From the command line, switch to the directory where dompdf will reside and run the following commands:

```
git clone https://github.com/dompdf/dompdf.git
cd dompdf/lib

git clone https://github.com/PhenX/php-font-lib.git php-font-lib
cd php-font-lib
git checkout 0.5.1
cd ..

git clone https://github.com/PhenX/php-svg-lib.git php-svg-lib
cd php-svg-lib
git checkout v0.3.2
cd ..

git clone https://github.com/sabberworm/PHP-CSS-Parser.git php-css-parser
cd php-css-parser
git checkout 8.1.0
```

Require dompdf and it's dependencies in your PHP. For details see the [autoloader in the utils project](https://github.com/dompdf/utils/blob/master/autoload.inc.php).

Quick Start
-----------

[](#quick-start)

Just pass your HTML in to dompdf and stream the output:

```
// reference the Dompdf namespace
use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');

// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to Browser
$dompdf->stream();
```

### Setting Options

[](#setting-options)

Set options during dompdf instantiation:

```
use Dompdf\Dompdf;
use Dompdf\Options;

$options = new Options();
$options->set('defaultFont', 'Courier');
$dompdf = new Dompdf($options);
```

or at run time

```
use Dompdf\Dompdf;

$dompdf = new Dompdf();
$options = $dompdf->getOptions();
$options->setDefaultFont('Courier');
$dompdf->setOptions($options);
```

See [Dompdf\\Options](src/Options.php) for a list of available options.

### Resource Reference Requirements

[](#resource-reference-requirements)

In order to protect potentially sensitive information Dompdf imposes restrictions on files referenced from the local file system or the web.

Files accessed through web-based protocols have the following requirements:

- The Dompdf option "isRemoteEnabled" must be set to "true"
- PHP must either have the curl extension enabled or the allow\_url\_fopen setting set to true

Files accessed through the local file system have the following requirement:

- The file must fall within the path(s) specified for the Dompdf "chroot" option

Limitations (Known Issues)
--------------------------

[](#limitations-known-issues)

- Table cells are not pageable, meaning a table row must fit on a single page.
- Elements are rendered on the active page when they are parsed.
- Embedding "raw" SVG's (``) isn't working yet, you need to either link to an external SVG file, or use a DataURI like this: ```
    $html = '';
    ```

    Watch [dompdf/dompdf#320](https://github.com/dompdf/dompdf/issues/320) for progress
- Does not support CSS flexbox.
- Does not support CSS Grid.

---

[![Donate button](https://camo.githubusercontent.com/acff8a4af46413276118b9f3b883b373601ac053d9dd5acf8a4e8a944c2538a9/68747470733a2f2f7777772e70617970616c2e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e6174655f534d2e676966)](http://goo.gl/DSvWf)

*If you find this project useful, please consider making a donation. Any funds donated will be used to help further development on this project.)*

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~135 days

Recently: every ~118 days

Total

27

Last Release

954d ago

Major Versions

v0.8.6 → v1.0.02020-12-24

v1.2.2 → v2.0.02022-06-21

PHP version history (4 changes)v0.7.0-betaPHP &gt;=5.3.0

v0.8.2PHP &gt;=5.4.0

v0.8.4PHP ^7.1

v1.0.0PHP ^7.1 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/798ee906929abfb6fc44fb15400d7f0058dc60ed0b14367a331250f980075da3?d=identicon)[tekintian](/maintainers/tekintian)

---

Top Contributors

[![bsweeney](https://avatars.githubusercontent.com/u/485897?v=4)](https://github.com/bsweeney "bsweeney (642 commits)")[![Mellthas](https://avatars.githubusercontent.com/u/5852189?v=4)](https://github.com/Mellthas "Mellthas (365 commits)")[![PhenX](https://avatars.githubusercontent.com/u/42170?v=4)](https://github.com/PhenX "PhenX (233 commits)")[![simonberger](https://avatars.githubusercontent.com/u/7163526?v=4)](https://github.com/simonberger "simonberger (47 commits)")[![gabrielbull](https://avatars.githubusercontent.com/u/671923?v=4)](https://github.com/gabrielbull "gabrielbull (38 commits)")[![barryvdh](https://avatars.githubusercontent.com/u/973269?v=4)](https://github.com/barryvdh "barryvdh (18 commits)")[![flaviencrochard](https://avatars.githubusercontent.com/u/564388?v=4)](https://github.com/flaviencrochard "flaviencrochard (13 commits)")[![samuferenc](https://avatars.githubusercontent.com/u/14260068?v=4)](https://github.com/samuferenc "samuferenc (6 commits)")[![tomlankhorst](https://avatars.githubusercontent.com/u/675432?v=4)](https://github.com/tomlankhorst "tomlankhorst (6 commits)")[![ThomasLandauer](https://avatars.githubusercontent.com/u/1054469?v=4)](https://github.com/ThomasLandauer "ThomasLandauer (6 commits)")[![staabm](https://avatars.githubusercontent.com/u/120441?v=4)](https://github.com/staabm "staabm (5 commits)")[![lquast](https://avatars.githubusercontent.com/u/10726291?v=4)](https://github.com/lquast "lquast (4 commits)")[![amacneil](https://avatars.githubusercontent.com/u/637671?v=4)](https://github.com/amacneil "amacneil (4 commits)")[![PHPGangsta](https://avatars.githubusercontent.com/u/608408?v=4)](https://github.com/PHPGangsta "PHPGangsta (4 commits)")[![eddturtle](https://avatars.githubusercontent.com/u/902607?v=4)](https://github.com/eddturtle "eddturtle (4 commits)")[![rudiedirkx](https://avatars.githubusercontent.com/u/168024?v=4)](https://github.com/rudiedirkx "rudiedirkx (4 commits)")[![IonBazan](https://avatars.githubusercontent.com/u/1985514?v=4)](https://github.com/IonBazan "IonBazan (4 commits)")[![williamdes](https://avatars.githubusercontent.com/u/7784660?v=4)](https://github.com/williamdes "williamdes (3 commits)")[![andreasnij](https://avatars.githubusercontent.com/u/1712334?v=4)](https://github.com/andreasnij "andreasnij (3 commits)")[![Cyrille37](https://avatars.githubusercontent.com/u/368965?v=4)](https://github.com/Cyrille37 "Cyrille37 (3 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/tekintian-dompdf/health.svg)

```
[![Health](https://phpackages.com/badges/tekintian-dompdf/health.svg)](https://phpackages.com/packages/tekintian-dompdf)
```

###  Alternatives

[dompdf/dompdf

DOMPDF is a CSS 2.1 compliant HTML to PDF converter

11.1k169.8M608](/packages/dompdf-dompdf)

PHPackages © 2026

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