PHPackages                             grasenhiller/silverstripe-wkhtmltox - 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. grasenhiller/silverstripe-wkhtmltox

ActiveSilverstripe-vendormodule[PDF &amp; Document Generation](/categories/documents)

grasenhiller/silverstripe-wkhtmltox
===================================

Create pdfs and images out of SilverStripe with WkHtmlToX

1.0.2(7y ago)15.6k2[1 issues](https://github.com/grasenhiller/silverstripe-wkhtmltox/issues)[1 PRs](https://github.com/grasenhiller/silverstripe-wkhtmltox/pulls)BSD-3-ClausePHP

Since Feb 20Pushed 4y agoCompare

[ Source](https://github.com/grasenhiller/silverstripe-wkhtmltox)[ Packagist](https://packagist.org/packages/grasenhiller/silverstripe-wkhtmltox)[ Docs](https://github.com/grasenhiller/silverstripe-wkhtmltox)[ RSS](/packages/grasenhiller-silverstripe-wkhtmltox/feed)WikiDiscussions master Synced today

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

SilverStripe WkHtmlToX
======================

[](#silverstripe-wkhtmltox)

Create pdfs and images out of SilverStripe with WkHtmlToX. Based on [WkHtmlToPdf](http://wkhtmltopdf.org/) and [mikehaertl's php wrapper](https://github.com/mikehaertl/phpwkhtmltopdf).

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

[](#installation)

### SilverStripe Module

[](#silverstripe-module)

```
$ composer require grasenhiller/silverstripe-wkhtmltox
```

### WkHtmlToX Binaries

[](#wkhtmltox-binaries)

[WKHtmlToPdf](http://wkhtmltopdf.org/) must be installed on your server to use this module. If it's not, you can try to use the provided binaries (v. 0.12.5). To do so, at first login via SSH and go into your home directory.

```
cd ~
mkdir ~/wkhtmltox
tar -xjvf vendor/grasenhiller/silverstripe-wkhtmltox/wkhtmltox_binaries.tar.bz2 -C ~/wkhtmltox
chmod 755 ~/wkhtmltox/wkhtmltopdf
chmod 755 ~/wkhtmltox/wkhtmltoimage

```

After this, if you're typing `./wkhtmltox/wkhtmltopdf -V` you should see the version number. Now it **should** work ;)

At last you need to provide the correct path to the binaries. Inside your `.env` file, define these environment variables

```
SS_WKHTMLTOPDF_BINARY='/absolute/path/to/wkhtmltox/wkhtmltopdf'
SS_WKHTMLTOIMAGE_BINARY='/absolute/path/to/wkhtmltox/wkhtmltoimage'

```

To get the absolute path, go into our wkhtmltox directory and type `pwd`;

```
cd ~/wkhtmltox/
pwd

```

Behind a proxy?
---------------

[](#behind-a-proxy)

You could define global proxy settings inside your `.env` file

```
SS_PROXY="http://user:password@192.168.1.2:8080"

```

or without the need for authentication

```
SS_PROXY="http://192.168.1.2:8080"

```

Change binary paths
-------------------

[](#change-binary-paths)

You can define a different binary path for wkhtmltopdf and wkhtmtltoimage inside your `.env` file

```
SS_WKHTMLTOPDF_BINARY='/path/to/wkhtmltopdf'
SS_WKHTMLTOIMAGE_BINARY='/path/to/wkhtmltoimage'

```

BasicAuth protected environment?
--------------------------------

[](#basicauth-protected-environment)

If you're working on a protected environment (dev?) and want to create pdfs or images from "locale" content, you need to define your BasicAuth credentials inside your `.env` file

```
SS_WKHTMLTOX_USERNAME
SS_WKHTMLTOX_PASSWORD

```

WkHtmlToX help/docs and examples?
---------------------------------

[](#wkhtmltox-helpdocs-and-examples)

Navigate to `http://your-website.tld/gh-wkhtmltox/`

Configuration (YML)
-------------------

[](#configuration-yml)

TBD

Methods for both, pdf and image creation
----------------------------------------

[](#methods-for-both-pdf-and-image-creation)

These methods work with `new WkPdf()` and `new WkImage()`

### Set folder where files should be saved

[](#set-folder-where-files-should-be-saved)

```
$pdf = new WkPdf();
$pdf->setFolder('folder/beneath/assets/to/save');
```

### Generate html from SilverStripe templates

[](#generate-html-from-silverstripe-templates)

- **$obj**: The dataobject or page you want to render
- **$variables**: An array with extra data (optional)
- **$template**: The desired template (optional)

```
$pdf = new WkPdf();
$html = $pdf::get_html($obj, $variables = [], $template = '');
```

### Replace relative image links

[](#replace-relative-image-links)

HTMLEditorFields normally don't store image links with absolute links. But WkHtmlToX needs absolute links to work. So just replace them with this method.

```
$pdf = new WkPdf();
$html = $pdf::get_html($obj);
$html = $pdf::replace_img_paths($html);
```

### Get options the pdf or image will be created with

[](#get-options-the-pdf-or-image-will-be-created-with)

Get all options

```
$pdf = new WkPdf();
echo '';
print_r($pdf->getOptions());
echo ';
die();
```

Get a specific option

```
$pdf = new WkPdf();
echo $pdf->getOption('name_of_option');
die();
```

### Set (new) or remove (existing) options

[](#set-new-or-remove-existing-options)

setOptions() setOption() removeOption() removeOptions()

Sry, no time to finish the readme until now ...
===============================================

[](#sry-no-time-to-finish-the-readme-until-now-)

### Overwrite global options

[](#overwrite-global-options)

Simple Example
--------------

[](#simple-example)

```
	private static $allowed_actions = [
		'pdfExport',
	];

	public function pdfExport() {
		$stylesheet = 'resources/vendor/grasenhiller/silverstripe-intranet-wiki/client/css/pdf.css';

		$filter = URLSegmentFilter::create();
		$filename = $filter->filter($this->MenuTitle);
		$filename .= '__' . date('Y-m-d') . '.pdf';

		$baseUrl = Director::absoluteBaseURL();

		$pdf = new WkPdf();
		$pdf->setOption('margin-top', 20);
		$pdf->setOption('margin-bottom', 20);
		$pdf->setOption('margin-left', 15);
		$pdf->setOption('margin-right', 15);
		$pdf->setOption('user-style-sheet', $stylesheet);
		$pdf->setOption('header-html', $baseUrl . 'gh-wkhtmltox/header?template=Grasenhiller\Intranet\Wiki\Pages\Pdf\Header');
		$pdf->setOption('footer-html', $baseUrl . 'gh-wkhtmltox/footer?template=Grasenhiller\Intranet\Wiki\Pages\Pdf\Footer');
		$pdf->setOption('header-spacing', 5);
		$pdf->setOption('footer-spacing', 5);

		$html = $pdf::get_html($this);

		$pdf->add($html);
		$pdf->download($filename);
	}
```

Header &amp; footer
-------------------

[](#header--footer)

gh-wkhtmltox/header gh-wkhtmltox/footer $all\_variables + variables from docs

### Specific basic auth

[](#specific-basic-auth)

Helpful
-------

[](#helpful)

viewport-size zoom 1.045 window-status h1 { page-break-before: always; }

px &amp; dpi

WkImage
-------

[](#wkimage)

add() construct

WkPdf
-----

[](#wkpdf)

add() construct

WkImage + WkPdf
---------------

[](#wkimage--wkpdf)

preview() download() save() getAsString()

WkController
------------

[](#wkcontroller)

- docs
- demo
- header + hook
- footer + hook

Config
------

[](#config)

- pdf global
- pdf "pages" predefined + custom
- image global + custom
- bypass\_proxy\_for\_own\_site

templates
---------

[](#templates)

html!

Todo
----

[](#todo)

- Set Options setz mehrere optionen + set / get global options
- Statische Links ersetzen bei get\_html (als Option)
- Stylesheets (user-style-sheet)
- Kommentare durchgehen
- README!
- IDE Annotation

Known Bugs
----------

[](#known-bugs)

- Header / Footer can't be loaded

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 75% 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 ~16 days

Total

3

Last Release

2605d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/9002671?v=4)[Benedikt Hofstätter](/maintainers/bhofstaetter)[@bhofstaetter](https://github.com/bhofstaetter)

---

Top Contributors

[![bhofstaetter](https://avatars.githubusercontent.com/u/9002671?v=4)](https://github.com/bhofstaetter "bhofstaetter (3 commits)")[![gheggie](https://avatars.githubusercontent.com/u/220231?v=4)](https://github.com/gheggie "gheggie (1 commits)")

---

Tags

pdfwkhtmltopdfsilverstripewkhtmltoimagegenerate imagewkhtmltoxcreate-pdfgenerate pdfcreate image

### Embed Badge

![Health badge](/badges/grasenhiller-silverstripe-wkhtmltox/health.svg)

```
[![Health](https://phpackages.com/badges/grasenhiller-silverstripe-wkhtmltox/health.svg)](https://phpackages.com/packages/grasenhiller-silverstripe-wkhtmltox)
```

###  Alternatives

[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[mikehaertl/phpwkhtmltopdf

A slim PHP wrapper around wkhtmltopdf with an easy to use and clean OOP interface

1.6k20.0M44](/packages/mikehaertl-phpwkhtmltopdf)[mvlabs/mvlabs-snappy

MvlabsSnappy is a Zend Framework and Laminas module that allow easy to thumbnail, snapshot or PDF generation from a url or a html page using Snappy PHP wrapper for the wkhtmltopdf/wkhtmltoimage conversion utility.

2453.6k](/packages/mvlabs-mvlabs-snappy)[lucasromanojf/laravel5-pdf

Provides the HTML2PDF functionality using the wkhtmltopdf library (Laravel 5)

1271.8k](/packages/lucasromanojf-laravel5-pdf)[symbiote/silverstripe-pdfrendition

A module that makes use of the Flying Saucer XHTML renderer project to create PDFs from XHTML pages.

175.0k](/packages/symbiote-silverstripe-pdfrendition)[luketowers/oc-snappypdf-plugin

SnappyPDF integration for OctoberCMS

121.1k](/packages/luketowers-oc-snappypdf-plugin)

PHPackages © 2026

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