PHPackages                             spacetab-io/wkhtmltopdf - 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. spacetab-io/wkhtmltopdf

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

spacetab-io/wkhtmltopdf
=======================

Non-blocking PHP wrapper for wkhtmltopdf built with AMP.

1.0.3(5y ago)310.6k↓25%2MITPHPPHP &gt;=7.4

Since Apr 28Pushed 5y ago2 watchersCompare

[ Source](https://github.com/spacetab-io/wkhtmltopdf-php)[ Packagist](https://packagist.org/packages/spacetab-io/wkhtmltopdf)[ RSS](/packages/spacetab-io-wkhtmltopdf/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (9)Versions (4)Used By (0)

Non-blocking WkHTMLtoPDF
========================

[](#non-blocking-wkhtmltopdf)

[![CircleCI](https://camo.githubusercontent.com/dfb098dca57d80c66d062003054ac9092c876e5188f5190aa337eb602be5ace5/68747470733a2f2f636972636c6563692e636f6d2f67682f73706163657461622d696f2f776b68746d6c746f7064662d7068702f747265652f6d61737465722e7376673f7374796c653d737667)](https://circleci.com/gh/spacetab-io/wkhtmltopdf-php/tree/master)[![codecov](https://camo.githubusercontent.com/df3c1cc5b2faf007e1b5b0f3e8bd0beb652f532542c871e6450e46726f1f0cd5/68747470733a2f2f636f6465636f762e696f2f67682f73706163657461622d696f2f776b68746d6c746f7064662d7068702f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/spacetab-io/wkhtmltopdf-php)

Non-blocking PHP wrapper for `wkhtmltopdf` and `wkhtmltoimage` built with [AMP](https://amphp.org).

Table of contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Why?](#why)
- [Installation](#installation)
- Usage
    - [On your machine](#on-your-machine)
        - [Simple cases](#simple-cases)
        - [Parallel](#parallel)
        - [Option Groups](#option-groups)
    - [Docker](#docker)
- [License](#license)

Features
--------

[](#features)

- An elegant interface to usage
- Create PDF files from HTML or URI strings
- Create Image files from HTML or URI string
- Faster than others because can be run in parallel (native)
- In-the-box your can use `OptionGroup` feature to group options for different cases

Why
---

[](#why)

Existing wrappers are slow, uses blocking API and does not have a normal object-oriented interface (for options).

It prevents to write fast and more elegant programming code.

Installation
------------

[](#installation)

```
composer require spacetab-io/wkhtmltopdf
```

Usage
-----

[](#usage)

### On your machine

[](#on-your-machine)

#### Simple cases

[](#simple-cases)

1. Create a PDF file from HTML string and save it to current directory:

```
use Amp\Loop;
use Spacetab\WkHTML;

Loop::run(static fn() =>
  yield WkHTML\ToPDF::new()->fromHtml('hello world')->asFile('hi.pdf')
);
```

2. Create a PDF file from URI and save it to current directory:

```
use Amp\Loop;
use Spacetab\WkHTML;

Loop::run(static fn() =>
  yield WkHTML\ToPDF::new()->fromUrl('https://google.com')->asFile('google.pdf')
);
```

3. Create a PDF file with custom options:

```
use Amp\Loop;
use Spacetab\WkHTML;
use Spacetab\WkHTML\OptionBuilder;

Loop::run(static function () {
  $option = new OptionBuilder\PDF();
  $option->addGrayscale();

  yield WkHTML\ToPDF::new()->fromUrl('https://google.com')->asFile('google.pdf');
});
```

Note: By default uses `UTF-8` encoding.

#### Parallel

[](#parallel)

It simple! Right?

```
Loop::run(static fn() =>
    yield [
        WkHTML\ToPDF::new()->fromHtml('hi1')->asFile('hi1.pdf'),
        WkHTML\ToPDF::new()->fromHtml('hi2')->asFile('hi2.pdf'),
        WkHTML\ToPDF::new()->fromHtml('hi3')->asFile('hi3.pdf'),
    ]
);
```

#### Option Groups

[](#option-groups)

So, if you work with many reports or create PDF files with set of different options you can be attempt to use option groups. Sample:

```
use Amp\Loop;
use Spacetab\WkHTML;
use Spacetab\WkHTML\OptionBuilder;
use Spacetab\WkHTML\OptionBuilder\OptionBuilderInterface;
use Spacetab\WkHTML\OptionGroup\OptionGroupInterface;

Loop::run(static function () {
    $pdf = new WkHTML\ToPDF(new class implements OptionGroupInterface {
        public function __invoke(): OptionBuilderInterface {
            $option = new OptionBuilder\PDF();
            $option->addGrayscale();

            return $option;
        }
    });

    yield $pdf->fromUrl('https://google.com')->asFile('google.pdf');
});
```

### Docker

[](#docker)

For usage in Docker your can like to use this image:

```
FROM spacetabio/amphp-alpine:7.4-wkhtmltopdf-1.1.0

COPY * /app

# cli commands should be created in the responsible service.
CMD ["bin/service", "run"]
```

This library tested in Docker container above in Circle CI.

License
-------

[](#license)

The MIT License

Copyright © 2021 spacetab.io, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

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

Total

3

Last Release

2164d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/35d8eff4a3e66b58f3e2af56fe948035469de1e19ac29c532d65c681955bbd18?d=identicon)[Roquie](/maintainers/Roquie)

---

Top Contributors

[![roquie](https://avatars.githubusercontent.com/u/3214290?v=4)](https://github.com/roquie "roquie (21 commits)")

---

Tags

amphpasyncphpphp74wkhtmltoimagewkhtmltopdf

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/spacetab-io-wkhtmltopdf/health.svg)

```
[![Health](https://phpackages.com/badges/spacetab-io-wkhtmltopdf/health.svg)](https://phpackages.com/packages/spacetab-io-wkhtmltopdf)
```

###  Alternatives

[danog/madelineproto

Async PHP client API for the telegram MTProto protocol.

3.4k855.0k18](/packages/danog-madelineproto)[mpdf/mpdf

PHP library generating PDF files from UTF-8 encoded HTML

4.7k77.1M493](/packages/mpdf-mpdf)[amphp/redis

Efficient asynchronous communication with Redis servers, enabling scalable and responsive data storage and retrieval.

165634.7k44](/packages/amphp-redis)[sensiolabs/gotenberg-bundle

A Symfony bundle that provides seamless integration with Gotenberg for generating PDFs and screenshots from various sources (HTML, Markdown, Office documents, URLs) with a clean, builder-based API.

210210.4k2](/packages/sensiolabs-gotenberg-bundle)[pontedilana/php-weasyprint

PHP library allowing PDF generation from an url or a html page. Wrapper for Kozea/WeasyPrint.

761.1M7](/packages/pontedilana-php-weasyprint)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)

PHPackages © 2026

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