This project is not covered by Drupal’s security advisory policy.

This module integrates Drupal with Go-WkhtmltoX.

Installation

Install as usual, see Installing Drupal 8 Modules or Installing modules' Composer dependencies for further information.

Configuration

Add your endpoint to your settings.php

$config['go_wkhtmltox.settings']['endpoint'] = 'http://wkhtmltox:8080';

PDF example

use Drupal\go_wkhtmltox\API\Converter\ToPdfConverter;
use Drupal\go_wkhtmltox\API\Fetcher\DataFetcher;

$pdf = [
 '#type' => 'inline_template',
 '#template' => '<h1>Hello world!</h1>',
];

$pdf_data = (string) \Drupal::service('renderer')->renderPlain($pdf);
$converter = new ToPdfConverter();
$converter->setOption('extend', [
  'dpi' => '300',
  'image-dpi' => '300',
  'image-quality' => '100',
  'page-width' => '210mm',
  'page-height' => '297mm',
]);
$fetcher = new DataFetcher();
$fetcher->setParam('data', $pdf_data);
$pdf_file = \Drupal::service('go_wkhtmltox.client')->convert($converter, $fetcher);

Image example

use Drupal\go_wkhtmltox\API\Converter\ToImageConverter;
use Drupal\go_wkhtmltox\API\Fetcher\DataFetcher;

$pdf = [
  '#type' => 'inline_template',
  '#template' => '<h1>Hello world!</h1>',
];

$pdf_data = (string) \Drupal::service('renderer')->renderPlain($pdf);
$converter = new ToImageConverter();
$converter->setOption('format', 'png');
// Sets the minimum value, it'll be auto-calculated.
$converter->setOption('width', 0);
$converter->setOption('extend', [
  'transparent' => '--transparent',
  // This option isn't added by itself.
  // @see https://github.com/gogap/go-wkhtmltox/issues/8
  'quality' => '0',
]);
$fetcher = new DataFetcher();
$fetcher->setParam('data', $pdf_data);
$pdf_file = \Drupal::service('go_wkhtmltox.client')->convert($converter, $fetcher);

Sponsors

- Fundación UNICEF Comité Español

Supporting organizations: 

Project information

Releases